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

Ghostscript与ps2pdf的关联及Mac系统字体调用差异问题

为什么ps2pdf能识别Mac系统字体而直接用Ghostscript(gs)命令不行?

问题背景

在Mac上,系统字体/System/Library/Fonts/Supplemental/GillSans.ttc存在的情况下,PostScript文件中通过/GillSans findfont调用该字体:

/GillSans14 {/GillSans findfont 14 scalefont setfont} def
...
GillSans14
boxl boxwid 4 div add boxt 20 sub m (JANUARY 2024) center

使用ps2pdf testfile.ps能成功生成带有Gill Sans字体的PDF,但直接执行:

gs -sDEVICE=pdfwrite -o testfile.pdf testfile.ps

时,Ghostscript会提示找不到GillSans字体,最终用Helvetica-Bold替代。两者均为Homebrew安装,路径都在/opt/homebrew/bin/。

核心原因

ps2pdf本质是封装Ghostscript的脚本,但它会自动添加一系列针对字体搜索的默认参数,而直接调用gs时没有这些配置:

  • ps2pdf会自动将Mac系统字体目录(包括/System/Library/Fonts/、/System/Library/Fonts/Supplemental/、~/Library/Fonts/等)加入Ghostscript的字体搜索路径,通过-I参数指定额外的资源目录。
  • 直接调用gs时,默认仅搜索Ghostscript自身安装目录下的Resource/Font目录,不会主动扫描系统字体位置,因此无法定位到GillSans.ttc。

验证与解决方法

  1. 查看ps2pdf的实际参数:执行ps2pdf -dDEBUG testfile.ps,可以看到脚本传给gs的命令中包含多个指向系统字体目录的-I参数。
  2. 手动给gs添加参数模拟ps2pdf的行为:
gs -I/System/Library/Fonts/ -I/System/Library/Fonts/Supplemental/ -sDEVICE=pdfwrite -o testfile.pdf testfile.ps

此时Ghostscript就能正常找到GillSans字体,生成正确的PDF。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 00:14:57