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。
验证与解决方法
- 查看ps2pdf的实际参数:执行
ps2pdf -dDEBUG testfile.ps,可以看到脚本传给gs的命令中包含多个指向系统字体目录的-I参数。 - 手动给
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
相关产品推荐
相关产品推荐

