如何将PDF转换为没有字体损失的图像?

时间:2019-02-25 06:56:40

标签: ghostscript imagemagick-convert pdftoppm

我已经阅读了许多有关将PDF(转换为带有ghostscript)的字体转换为图像时的字体问题的stackoverflow问题。

因为您没有嵌入字体,所以Ghostscript会尝试在系统中查找替代字体并提供更好的呈现方式。

但是我不明白为什么我的MacOSX Preview可以完美呈现PDF,而ghostscript无法呈现。

gs -sFONTPATH=/Library/Fonts -sDEVICE=pngalpha -o file-%03d.png -r144 my.pdf 

我什至告诉gs字体在哪里。

这是输出。

$ pdffonts cv18.pdf 

Fontconfig warning: "/usr/local/etc/fonts/fonts.conf", line 86: unknown element "blank"
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
CenturyGothic,Bold                   TrueType          WinAnsi          no  no  no      13  0
CenturyGothic                        TrueType          WinAnsi          no  no  no      14  0
CourierNew                           TrueType          WinAnsi          no  no  no      15  0
Arial                                TrueType          WinAnsi          no  no  no      16  0
AYTOPC+Wingdings                     TrueType          WinAnsi          yes yes no      17  0
TimesNewRoman                        TrueType          WinAnsi          no  no  no      18  0
CenturyGothic,Italic                 TrueType          WinAnsi          no  no  no      24  0


$ gs -sDEVICE=pngalpha -o file-%03d.png -r300 cv18.pdf 

GPL Ghostscript 9.26 (2018-11-20)
Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
Querying operating system for font files...
Substituting font NewCenturySchlbk-Bold for CenturyGothic,Bold.
Loading C059-Bold font from /usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/C059-Bold... 4357236 2918185 2219472 869812 4 done.
Substituting font NewCenturySchlbk-Roman for CenturyGothic.
Loading C059-Roman font from /usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/C059-Roman... 4504148 3145674 2313416 951449 4 done.
Substituting font Courier for CourierNew.
Loading NimbusMonoPS-Regular font from /usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/NimbusMonoPS-Regular... 4731860 3382093 2548760 1140366 4 done.
Can't find (or can't open) font file /usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/ArialMT.
Can't find (or can't open) font file ArialMT.
Can't find (or can't open) font file /usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/ArialMT.
Can't find (or can't open) font file ArialMT.
Didn't find this font on the system!
Substituting font Helvetica for ArialMT.
Loading NimbusSans-Regular font from /usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/NimbusSans-Regular... 4939372 3576328 2589160 1183936 4 done.
Can't find (or can't open) font file /usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/TimesNewRomanPSMT.
Can't find (or can't open) font file TimesNewRomanPSMT.
Can't find (or can't open) font file /usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/TimesNewRomanPSMT.
Can't find (or can't open) font file TimesNewRomanPSMT.
Didn't find this font on the system!
Substituting font Times-Roman for TimesNewRomanPSMT.
Loading NimbusRoman-Regular font from /usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/NimbusRoman-Regular... 5196116 3849418 3003064 1540393 4 done.
Page 2
Substituting font NewCenturySchlbk-Roman for CenturyGothic.
Substituting font NewCenturySchlbk-Bold for CenturyGothic,Bold.
Substituting font NewCenturySchlbk-Italic for CenturyGothic,Italic.
Loading C059-Italic font from /usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/C059-Italic... 5504628 4138508 2467960 1088660 4 done.

问题是:为什么MacOSX Preview没有这个问题?从哪里获取字体才能完美呈现?

1 个答案:

答案 0 :(得分:0)

我需要查看您的PDF文件才能发表评论,但是在您说“我什至告诉gs字体在哪里”的地方,恐怕这似乎不正确。

Ghostscript反向频道说:

找不到(或无法打开)字体文件/usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/ArialMT。

因此该文件不存在,或者Ghostscript无法打开它,或者它可能以某种方式损坏了。

fontconfig是您唯一用来“告诉gs字体在哪里”的东西吗?因为如果是这样,您实际上并没有告诉Ghostscript任何东西。另请注意fontconfig警告,我不是font config的专家,但我怀疑您可能也希望对此进行整理。

Ghostscript可能会或可能不会使用fontconfig,具体取决于它的构建方式,这显然是我所不知道的。如果您实际上要告诉 Ghostscript 有关字体(而不是fontconfig)的信息,则可能会更好。您需要使用-I(包括)开关来编辑/创建fontmap.GS文件,并告诉Ghostscript在哪里找到它。

您可以在/ ghostscript / Resource / Init中找到示例fontmap.GS

为了提供更多帮助,我需要知道字体文件所在的确切路径,用来告诉Ghostscript字体文件所在位置的方法以及fontmap.GS的确切配置(或无论您使用的是什么)。如果字体文件以某种方式损坏,则PDF文件和字体文件也将很有帮助。我还对ArialMT和C059-Roman字体的格式感到好奇。 PostScript或TrueType字体?