You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PDFCROP调用GhostScript执行失败问题求助(Windows 10环境)

PDFCROP 1.40在Windows 10 Enterprise 64位下调用Ghostscript失败的问题

问题现象

在Windows 10 Enterprise 64位系统中使用PDFCROP 1.40时,出现错误:

!!! Error: Cannot call ghostscript `mgs' (No such file or directory/The system cannot find the file specified)!

Debug输出信息

pdfcrop --debug --margins "1 1 1 1" "C:\test.pdf" "C:\test.pdf"
PDFCROP 1.40, 2020/06/06 - Copyright (c) 2002-2020 by Heiko Oberdiek, Oberdiek Package Support Group.

PDFCROP 1.40, 2020/06/06 - Copyright (c) 2002-2020 by Heiko Oberdiek, Oberdiek Package Support Group.
* Restricted mode: disabled
* Option `pdfversion': auto
* Perl executable: C:\Strawberry\perl\bin\perl.exe
* Perl version: v5.32.1
* Pointer size: 8
* Pipe support: yes
* Fork support: no
* OS name: MSWin32
* Arch name: MSWin32-x64-multi-thread
* System: miktex
* Not found (mgs): mgs.exe
* Found (mgs): C:\Users\Buckel\AppData\Local\Programs\MiKTeX\miktex\bin\x64\mgs.exe
* Autodetected ghostscript command: mgs
* Input file: test.pdf
* Output file: test.pdf
* Margins: 1 1 1 1
* PDF header: %PDF-1.7
* Using PDF version: 1.7
* Running ghostscript for BoundingBox calculation ...
* Ghostscript call: mgs -sDEVICE=bbox -dBATCH -dNOPAUSE -c save pop -f test.pdf
* Cleanup
* Temporary files: tmp-pdfcrop-8160.tex
!!! Error: Cannot call ghostscript `mgs' (No such file or directory/The system cannot find the file specified)!

当前环境

  • 系统:Windows 10 Enterprise 64位
  • PDFCROP:1.40(通过MiKTeX 4.8安装)
  • Perl:Strawberry Perl 64位 5.32.1.1-64bit
  • Ghostscript:9.56.1 64位

已尝试的操作

  • 完全卸载重装Ghostscript 9.52(2020旧版本)和MiKTeX 4.8
  • 调用pdfcrop时添加--gscmd gswin64参数
  • 设置环境变量MIKTEX_PREFERMIKTEXGHOSTSCRIPT=false
  • 检查%PATH%已包含相关路径
  • 手动执行debug中的mgs命令可正常返回边界框信息,但问题仍未解决

可行解决方案

1. 直接指定Ghostscript完整路径调用

执行pdfcrop时,通过--gscmd参数传入Ghostscript可执行文件的绝对路径,示例:

pdfcrop --margins "1 1 1 1" --gscmd "C:\Program Files\gs\gs9.56.1\bin\gswin64.exe" "C:\test.pdf" "C:\test.pdf"

请根据你的实际Ghostscript安装路径替换上述路径。

2. 修改PDFCROP脚本的Ghostscript命令

找到MiKTeX安装目录下的pdfcrop脚本(通常路径为C:\Users\Buckel\AppData\Local\Programs\MiKTeX\miktex\bin\x64\pdfcrop.pl),用文本编辑器打开后,找到自动检测Ghostscript的代码段,将默认的mgs替换为gswin64.exe或其完整路径,保存后重新调用pdfcrop。

3. 为mgs.exe创建硬链接到官方Ghostscript

以管理员身份打开命令提示符,执行以下命令(替换为你的实际路径):

mklink /H "C:\Users\Buckel\AppData\Local\Programs\MiKTeX\miktex\bin\x64\mgs.exe" "C:\Program Files\gs\gs9.56.1\bin\gswin64.exe"

此操作让pdfcrop调用mgs时,实际指向你安装的官方Ghostscript可执行文件。

4. 调整环境变量PATH的优先级

将Ghostscript的bin目录(如C:\Program Files\gs\gs9.56.1\bin)移到MiKTeX的bin目录之前,确保系统优先搜索到官方Ghostscript的可执行文件,而非MiKTeX的相关路径。

内容的提问来源于stack exchange,提问作者tobias_buckel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 02:40:40