Replace all font glyphs in a PDF by converting them to outline shapes

不想你离开。 提交于 2019-11-28 18:52:12

Yes, you can use Ghostscript to achieve what you want.

I. For Ghostscript versions up to 9.14

You need to go through 2 steps:

  1. Convert the PDF to a PostScript file, but use the side effect of a relatively unknown parameter: it is called -dNOCACHE. This will convert all used fonts to outline shapes:

    gs -o somepdf.ps -dNOCACHE -sDEVICE=pswrite somepdf.pdf
    
  2. Convert the PS back to PDF (and, maybe delete the intermediate PS again):

    gs -o somepdf-with-outlines.pdf -sDEVICE=pdfwrite somepdf.ps
    
    rm somepdf.ps
    

This method is not reliable long-term, because the Ghostscript developers have stated that -dNOCACHE may not be present in future versions.

Note: the resulting PDF will very likely be larger than the original one. Plus, without additional command line parameters, all images in the original PDF will likely also be processed according to Ghostscript builtin defaults. This can lead to unwanted side-effects. Those side-effects can be avoided by adding more command line parameters to do otherwise.


II. Ghostscript versions 9.15 or newer

Ghostscript version 9.15 (released in September 2014) supports a new command line parameter:

 -dNoOutputFonts

This will cause the output devices pdfwrite, ps2write and eps2write "to 'flatten' glyphs into 'basic' marking operations (rather than writing fonts to the output)".

This means: the two steps described for pre-9.15 GS versions can be avoided. The desired result can be achieved with a single command:

 gs -o file-with-outlines.pdf -dNoOutputFonts -sDEVICE=pdfwrite file.pdf

Note: the same caveat is true as already noted in part I. If your PDF includes images, there may be unwanted side effects introduced by the simple command line above. To avoid these, you need to add more specific parameters.

KenS

This commit adds a new switch -dNoOutputFonts to the Ghostscript pdfwrite and ps2write devices which will produce a PDF file (or PostScript, depending on the selected device) where all the glyphs have been created as vectors, not as text.

You will need at least version 9.15 of Ghostscript to get this feature. Be aware that the PDF file will almost certainly be larger and copy/paste/search will (obviously) not work.

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