TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to know the syntax to invoke GhostScript directly to get the same effect as each of the following command does.

  1. ps2pdf input.ps
  2. pdfcrop --hires input
  3. pdftops -eps input.pdf
  4. epstool --copy --bbox input.eps output.eps
  5. epstopdf --hires input.eps
share|improve this question
Use the source Luke! Use the source! – Martin Scharrer Jul 2 '11 at 8:56
@Martin: I cannot read perl script. – xport Jul 2 '11 at 9:01
@Jasper: Luke Skywalker. – Martin Scharrer Jul 2 '11 at 16:59
up vote 7 down vote accepted

You can get this by looking at the source code of these tools. Most of them are scripts, which compile a list of Ghostscript options depending on their command line options and execute it at the end. In order to get the $OPTIONS variables etc. decoded automatically you can make a copy of these scripts and add an echo before the final command so it is printed in the terminal and not executed. An even simpler alternative is to start them using $SHELL -x script --args which is the shell debug mode (at least for sh and bash) which prints all executed commands.

For your 1. I get:

gs -P- -dSAFER -q -P- -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sstdout=%stderr -sOutputFile=input.pdf -P- -dSAFER -c .setpdfwrite -f input.ps

Number 2. is a Perl script and is only using GS for the BBox extraction (as my fixbb script does I mentioned in your other question):

gs -sDEVICE=bbox -dBATCH -dNOPAUSE -c save pop -f input.pdf

Number 3. is a program not a script and uses libpoppler internally to do the conversion, not Ghostscript.

Number 4. again simply uses Ghostscript for BBox extraction which is then placed into the otherwise unchanged file. Here the BBox is written to a temp file first.

"gs"  -dNOPAUSE -dBATCH -sDEVICE=bbox   -c "> setpagedevice" -f "/tmp/gsviewnIk3kp"

Number 5 uses (displayed using the --debug option):

gs -q -dNOPAUSE -dSAFER -sDEVICE=pdfwrite -sOutputFile=input.pdf -dPDFSETTINGS=/prepress -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -dAutoRotatePages=/None - -c quit
share|improve this answer
by the way: the -dSAFER shouldn't be used when the converted PS file has to read and/or write from/to external files. It forbits such operations – Herbert Jul 2 '11 at 9:20
@xport: The GS command line argument should be about the same, maybe different styles (e.g. arguments start with / not -). In this case it would by batch scripts (.bat) but also here echo works. – Martin Scharrer Jul 2 '11 at 9:20
I think your answer for number 2 does not work as pdfcrop --hires input.pdf. – xport Jul 2 '11 at 9:43
@Martin: Are you sure that -P switch occurs thrice and -dSAFER option occurs twice in ps2pdf? – xport Jul 26 '11 at 3:31
Is there one for ps2eps input.ps as well? – highsciguy Apr 5 '13 at 6:20

Where is the problem? Do a cat `which ps2pdf` under Linux or type .... under Windows (don't know if it has the same "which" feature as Linux) .

epstool is a program not a script.

share|improve this answer
@Joseph: how do I get the backticks inside backticks? – Herbert Jul 2 '11 at 9:17
Press the edit button, you will see how to escape backtick. Inner backticks must be enclosed by a pair of double backticks. – xport Jul 2 '11 at 9:20
@xport: thanks, very easy ... :-) – Herbert Jul 2 '11 at 9:23
@Herbert: if I'm not wrong, starting from the NT family, Windows has now a command called where, which is very similar to the good old Linux which (it seems to incorporate some find features as well). :-) – Paulo Cereda Jul 2 '11 at 10:56

Most of these are shell/perl scripts so you can easily see what they do. They all do a bit (or a lot) more than simply invoking gs though, so I'll just give the main option they use. You'll have to read the code to see exactly what:

  1. -sDEVICE=pdfwrite
  2. -sDEVICE=bbox
  3. Not based on ghostscript!
  4. -sDEVICE=bbox
  5. -sDEVICE=pdfwrite
share|improve this answer
+1 but number 5 -sDEVICE=epswrite ? – xport Jul 2 '11 at 9:26
Nope. epstopdf is producing pdf, so it uses pdfwrite – Lev Bishop Jul 2 '11 at 9:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.