Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ghostscript: "Unrecoverable error: undefinedfilename in setpagedevice"

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.)]

like image 752
emacsomancer Avatar asked Dec 13 '14 00:12

emacsomancer


1 Answers

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):

  1. -SOutputFile=... does NOT work
  2. -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
like image 85
Spock Avatar answered Nov 15 '22 10:11

Spock