问题描述
我正在尝试使用ghostscript压缩pdf文件:
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--
[我将-SOutputFile的错字固定为-sOutputFile,以避免出现这种红色鲱鱼. (但这就是某些评论/答案所指的内容.)
推荐答案
这对我有用...
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/printer \
-dNOPAUSE \
-dQUIET \
-dBATCH \
-sOutputFile=output.pdf \
input.pdf
由-kp-编辑
要明确说明(并再次重申KenS在评论中写的内容):
To spell it out explicitly (and to re-iterate what KenS wrote in his comment):
-
-SOutputFile=...
不起作用 -
-sOutputFile=...
是正确的语法. (Ghostscript命令行参数区分大小写!)
-SOutputFile=...
does NOT work-sOutputFile=...
is the correct syntax. (Ghostscript command line parameters are case sensitive!)
此外,在最新版本的Ghostscript中,您现在可以使用-o output.pdf
而不是长版本. -o ...
也会自动隐式设置-dBATCH -dNOPAUSE
参数.因此,编写此命令的最短方法是:
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
这篇关于Ghostscript:“无法恢复的错误:setpagedevice中的未定义文件名"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!