TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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 am using TeXLive 2010 and do my job using the following workflow with 6 steps. I want to reduce the number of steps as minimal as possible because I will apply the workflow to the web based system.

  1. latex %1
  2. dvips %1
  3. ps2pdf -dPDFSETTINGS#/prepress %1.ps
  4. gswin32c -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dSAFER -dNOPAUSE -dQUIET -dBATCH -sOutputFile=%1-temp.pdf %1.pdf
  5. pdfcrop --hires %1-temp.pdf %1.pdf
  6. pdftops -eps %1.pdf

I know that the steps 3, 4 and 5 internally invoke GhostScript. Shortly speaking, how to combine them into a single GhostScript call?

My current effort

I have tried to combine the step 3 and 4 as follows and it works.

  1. latex %1
  2. dvips %1
  3. ps2pdf -dCompatibilityLevel=1.5 -dPDFSETTINGS#/prepress %1.ps
  4. rename %1.pdf %1-temp.pdf
  5. pdfcrop --hires %1-temp.pdf %1.pdf
  6. pdftops -eps %1.pdf

And I am still interested in combining steps 3 and 5 above.

share|improve this question
Why don't you use a small bash-script or a makefile? Then the number of steps are irrelevant. – Marco Daniel Jul 9 '11 at 9:40
@Marco: The above steps are extracted from my batch file. :-) You can see there are %1 placeholders that represent the file name without extension. – xport Jul 9 '11 at 9:46
Ah ok. I thought it was an example ;-) – Marco Daniel Jul 9 '11 at 9:50
up vote 1 down vote accepted

You can't combine steps 3 and 5. Steps 3&4 use -sDEVICE=pdfwrite so they can combine. Step 5 uses -sDEVICE=bbox to find the bbox. You need separate runs of gs to use separate devices.

You can eliminate your revised step 4 with the rename %1.pdf %1-temp.pdf by making step 3 as ps2pdf -dCompatibilityLevel#1.5 -dPDFSETTINGS#/prepress %1.ps %1-temp.pdf. By the way I needed to change = to # for -dCompatibilityLevel#1.5.

It's not worth trying to optimize this further. If you are planning to run this on a web system on user-supplied code then be aware of all the security risks. You better add -R to dvips, and be aware that pdfcrop executes pdftex internally (pdfcrop --restricted helps a little) and so on.

share|improve this answer
As pdfcrop executes pdftex internally, do we need to pass -interaction=nonstopmode to pdfcrop? – xport Jul 9 '11 at 17:46
No. Not necessary. – Lev Bishop Jul 9 '11 at 20:45

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.