cdecker
cdecker

Reputation: 4687

Calling ghostscript from a script produces error

I'm trying to automate some post-processing on scanned PDF documents. One tool I found was ghostscript that would compress the scanned images nicely. However when I try to call gs from inside my python script it fails miserably:

Error: /undefinedfilename in (/tmp/step-02-1.pdf)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push
Dictionary stack:
   --dict:1164/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 9.05: Unrecoverable error, exit code 1

The command line I'm trying to run is

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/screen\
   -dSAFER -dNOPAUSE -dQUIET -dBATCH -sOutputFile=/tmp/step-03-1.pdf\
   /tmp/step-02-1.pdf

Since this is a python script, I tried both os.system and os.popen to execute it, but to no avail. If I run the above command line from the shell it all works. Any idea where my error could be?

Upvotes: 2

Views: 1948

Answers (1)

KenS
KenS

Reputation: 31141

Well Ghostscript can't find the file, have you tried something simple like 'ls /tmp/step-02-1.pdf' instead of invoking GS ?

Does that work ?

Upvotes: 2

Related Questions