How can I convert a PDF to image with no font losses?

1.1k Views Asked by At

I have read tons of stackoverflow questions about problems with fonts when converting (with ghostscript) from PDF to image.

Because you don't have the fonts embedded, the ghostscript tries to find alternatives in your system and render the better possible.

But I can not understand why my MacOSX Preview is rendering perfect a PDF and ghostscript can't.

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

I'm even telling gs where the fonts are.

This is the output.

$ 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.

The question is: why MacOSX Preview is not having this problems? Where does it take the fonts from, to render perfectly ?

1

There are 1 best solutions below

0
On

I would need to see your PDF file to be able to comment, but where you say "I'm even telling gs where the fonts are", I'm afraid that does not appear to be correct.

The Ghostscript back channel says:

Can't find (or can't open) font file /usr/local/Cellar/ghostscript/9.26/share/ghostscript/9.26/Resource/Font/ArialMT.

So either the file does not exist, or Ghostscript can't open it or just possibly its corrupted in some way.

Is fontconfig the only thing you are using to 'tell gs where the fonts are' ? Because if so, you aren't really telling Ghostscript anything. Note also the fontconfig warning, I'm not an expert with font config, but I suspect you may want to sort that out too.

Ghostscript may, or may not, use fontconfig, depending how it was built, which obviously I don't know. If you were to actually tell Ghostscript about the fonts (instead of fontconfig) then it might work better. You would need to edit/create a fontmap.GS file and tell Ghostscript where to find it, using the -I (Include) switch.

You can find an example fontmap.GS in /ghostscript/Resource/Init

In order to help more I'd need to knwo the exact path where the font file is located, the method you are using to tell Ghostscript where the font file is located, and the exact configuration of the fontmap.GS (or whatever means you are using). The PDF file and font file would also be helpful, in case the font file is corrupted in some way. I;d also be curious about the format of the ArialMT and C059-Roman fonts. PostScript or TrueType fonts ?