I'm trying to compress pdf files 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 now it won't work. I get 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 fixed the typo from -SOutputFile to -sOutputFile to avoid this red herring. (But that is what some of the comments/answers are referring to.)]
This worked for me...
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/printer \
-dNOPAUSE \
-dQUIET \
-dBATCH \
-sOutputFile=output.pdf \
input.pdf
Edited by -kp-
To spell it out explicitly (and to re-iterate what KenS wrote in his comment):
-SOutputFile=...
does NOT work-sOutputFile=...
is the correct syntax. (Ghostscript command line parameters are case sensitive!)Also, with recent versions of Ghostscript, you can now use -o output.pdf
instead of the long version. -o ...
also automatically and implicitely sets the -dBATCH -dNOPAUSE
parameters. So the shortest way to write this command is:
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/printer \
-q \
-o output.pdf \
input.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With