Ghostscript: "Fatal error: undefinedfilename in setpagedevice"

I am trying to compress pdfs using ghostscript like this:

gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH  -sOutputfile=output.pdf input.pdf 

      

I've done this successfully in the past, but for some reason it won't work now. I am getting the following error:

GPL Ghostscript 9.15 (2014-09-22)
Copyright (C) 2014 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
**** Unable to open the initial device, quitting.
Unrecoverable error: undefinedfilename in setpagedevice
Operand stack:
    true  --nostringval--  --nostringval--  --nostringval--  --nostringval--  --nostringval--  --nostringval--  --nostringval--  --nostringval--

      

[Edit: I corrected the typo from -SOutputFile to -sOutputFile to avoid this red herring. (But that's what some of the comments / answers refer to.)]

+3


source to share


2 answers


This worked for me ...

gs \
   -sDEVICE=pdfwrite \
   -dCompatibilityLevel=1.4 \
   -dPDFSETTINGS=/printer \
   -dNOPAUSE \
   -dQUIET \
   -dBATCH \
   -sOutputFile=output.pdf \
    input.pdf

      

Edited: -kp -

To write it down explicitly (and reiterate what KenS wrote in his comment):



  • -SOutputFile=...

    Does not work
  • -SOutputFile=...

    - correct syntax. (Ghostscript command line options are case sensitive!)

Also, in recent versions of Ghostscript you can now use the -o output.pdf

long version instead. -o ...

also automatically and implicitly sets parameters -dBATCH -dNOPAUSE

. Therefore, the shortest way to write this command is:

gs                          \
   -sDEVICE=pdfwrite        \
   -dCompatibilityLevel=1.4 \
   -dPDFSETTINGS=/printer   \
   -q                       \
   -o output.pdf            \
    input.pdf

      

+6


source


Perhaps you just messed up your input and output filenames. I've done this before and got the same message. This is easy to do because the command for the output file comes before the input file.



0


source







All Articles