我正在尝试对扫描的 PDF 文档进行自动化一些后处理。我发现的一种工具是 Ghostscript,它可以很好地压缩扫描图像。然而,当我尝试从 python 脚本内部调用 gs
时,它惨败了:
Error: /undefinedfilename in (/tmp/step-02-1.pdf)
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1164/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 9.05: Unrecoverable error, exit code 1
我尝试运行的命令行是
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/screen\
-dSAFER -dNOPAUSE -dQUIET -dBATCH -sOutputFile=/tmp/step-03-1.pdf\
/tmp/step-02-1.pdf
由于这是一个Python脚本,我尝试了os.system
和os.popen
来执行它,但没有成功。如果我从 shell 运行上述命令行,一切都会正常。知道我的错误可能出在哪里吗?
最佳答案
Ghostscript 找不到该文件,您是否尝试过像“ls/tmp/step-02-1.pdf”这样简单的操作而不是调用 GS?
这有效吗?
关于python - 从脚本调用 Ghostscript 会产生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20020123/