Ghostscript: "Unrecoverable error: undefinedfilename in setpagedevice"
18,095
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
Author by
emacsomancer
I do things with lambda calculus. Mainly on natural language.
Updated on June 08, 2022Comments
-
emacsomancer almost 2 years
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.)]
-
emacsomancer over 9 yearsSorry for the typo. Unfortunately, even with the correct syntax (-sOutputFile) I still get exactly the same error.
-
emacsomancer over 9 yearsThough when I use the example at the end of your post (with the appropriate file names, of course), it works. Perhaps in the latest versions of
gs
-sOutputFile
no longer works? -
KenS over 9 yearsNo, OutputFile continues to work perfectly well. Try removing the PDFSETTINGS and CompatibilityLevel. In short, try to reduce the scope of the problem until you discover what it is that provokes the error. It sounds like you are getting the error due to using ebook. If so then instead set the configuration the same as the predefined settings, and then remove them one by one until you see the problem.
-
emacsomancer over 9 years@KenS I've tried removing various other bits, but nothing works as long as I have
-sOutputFile=output.pdf
. As soon as I switch to-o output.pdf
, it works. -
KenS over 9 yearsWell I know that works, I use it here all the time. I see you are on Linux, did you get the binaries from a distribution, or build them yourself ?
-
emacsomancer over 9 years@KenS - from a distribution. I'll have to play with it some more sometime to see what my issue is with
-sOutputFile
. -
KenS over 9 yearsI'd have to say it sound like the distribution has broken Ghostscript somehow (several distros make changes to Ghostscript when packaging it). Your best bet is probably to download the source and build it yourself. You might also report the problem as a bug to the distribution involved. All I cna tell you is that (built from source) -sOutputFile works well for me on Linux.