Rasterize PDF's with font not embedded using GhostScript

橙三吉。 提交于 2019-12-04 15:08:45

This was (eventually) answered where it started, on UseNet in comp.text.pdf. The problem is that the PDF file contains a reference to a CIDFont (not a font, a CIDFont). Contrary to the problem statement above the font is not embedded, and this is the difficulty.

CIDFonts are rather more complex than fonts, and it is not simple to substitute for missing fonts in the same way as missing Latin regular fonts are substituted with (for example) Courier.

It isn't possible to skip the font because Ghostscript can't know immediately where the text is going to be rendered (ie the font is loaded before we find out where the text is going to be drawn).

Now Ghostscript does allow you to specify additional fonts; in the case of CIDFonts these are described in the file called cidfmap which is located in gs/Resource/Init in the Ghostscript distribution.

Problem 1 is that by default GS has its resources built into the executable, and uses the file located in the ROM file system. So we need to tell GS to look on disk instead. There are two ways to do this:

1) Copy all the resources from the source distribution (everything under /gs/Resource) to a convenient location and use the -sGenericResourceDir= switch to tell GS to use this directory. If you do this then you must be careful to add a trailing directory separator to the end of the path. I mention this because normally with GS you don't do that. In this case the PLRM says we must.

2) Copy the cidfmap file somewhere convenient and tell GS to look in that directory by using the -I switch which adds the directory to the head of the search list. Its important that its the head, because you can only have one cidfmap file, and GS uses the first one it finds.

So, on to the font files themselves. You can either use a genuine CIDFont, or you can use a TrueType font as a substitute for a CIDFont.

If you use a genuine CIDFont then you must either use option 1 above (GenericResourceDir) and put the file in a directory named Resource/CIDFonts under the location of GenericResourceDir or you use option 2 and put the CIDFont in a directory named CIDFonts directly under the location pointed to by -I.

If you use a TrueType font as a substitute then you can use the /Path key in the entry for the font in cidfmap to point to the TrueType font.

The complexities of converting a TrueType font of unknown provenance into a specific type of CIDFont mean that you have to supply a lot of information in the cidfmap entry, this is documented in the file itself. Things to watch out for:

1) The /Path must point to the font file, it must be present and have permissions allowing it to be read.

2) You should supply a /SubfontID for a TrueType Collection. If you want to use anything except the first subfont then you must supply a SubfontID.

3) The entries in cidfmap are interpreted by a PostScript interpreter and so must conform to PostScript syntax. In particular the font name is a PostScript name object and so must be introduced with a '/'.

Finally; a number of Linux distributions do not ship the full source for Ghostscript, you may need to pick this up before using any of the advice above. You can get releases from here:

http://www.ghostscript.com/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!