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.)]
source to share
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
source to share