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

后端 未结 2 2121
误落风尘
误落风尘 2020-12-13 07:26

I am looking for a way to \'outline\' all text/fonts in a PDF file, i.e. convert them to curves.

I would prefer to do this without having to convert the PDF

相关标签:
2条回答
  • 2020-12-13 07:56

    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.

    0 讨论(0)
  • 2020-12-13 08:00

    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.

    0 讨论(0)
提交回复
热议问题