python - 从脚本调用 Ghostscript 会产生错误

标签 python pdf ghostscript

我正在尝试对扫描的 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.systemos.popen来执行它,但没有成功。如果我从 shell 运行上述命令行,一切都会正常。知道我的错误可能出在哪里吗?

最佳答案

Ghostscript 找不到该文件,您是否尝试过像“ls/tmp/step-02-1.pdf”这样简单的操作而不是调用 GS?

这有效吗?

关于python - 从脚本调用 Ghostscript 会产生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20020123/

相关文章:

vba - 选择多个 Excel 工作表导出为 PDF

ios - XCode 项目中的文件安全性

java - Ghost4J native 库将 pdf 转换为图像

pdf - 使用 Ghostscript 生成缩略图可旋转我的设备尺寸定义以实现横向 pdf 页面

python - Pandas 帮助: convert column from delimted string to column array

php - 如何最有效地将数据从网页输入到Python脚本

javascript - 如何从脚本中提取数据?

pdf - 在PDF中将RGB转换为CMYK的脚本(或其他方式)?

macos - 将 GhostScript 9.02 升级到 9.05

python - 使用错误 : unrecognized arguments: in %R line