Ghostscript: “Unrecoverable error: undefinedfilename in setpagedevice”

爱⌒轻易说出口 提交于 2019-12-10 16:29:07

问题


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


回答1:


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



回答2:


It could be that you have simply mixed up your input and output filenames. I have done that before and got the same message. It's easy to do, since the output file command comes before the input file.



来源:https://stackoverflow.com/questions/27454350/ghostscript-unrecoverable-error-undefinedfilename-in-setpagedevice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!