通过将其转换为轮廓形状来替换PDF中的所有字体字形 [英] Replace all font glyphs in a PDF by converting them to outline shapes

查看:678
本文介绍了通过将其转换为轮廓形状来替换PDF中的所有字体字形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来处理PDF文件中的所有文本/字体,即将其转换为曲线。



我宁愿这样做,而不必将PDF转换成PostScript,然后返回。另外,我想使用免费的轻量级跨平台工具,可以通过命令行自动执行,例如Ghostscript或MuPDF。

解决方案

是的,你可以使用Ghostscript来实现你想要的。

我。对于Ghostscript版本高达9.14



您需要经过2个步骤:


  1. 将PDF转换为PostScript文件,但使用相对未知参数的副作用:称为 -dNOCACHE 。这会将所有使用的字体转换成轮廓形状:

    $ $ p $ g $ -o somepdf.ps -dNOCACHE -sDEVICE = pswrite somepdf.pdf $转换PS回到PDF(也许,再删除中间的PS):

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

    rm somepdf。 ps


这种方法长期不可靠,因为Ghostscript开发者已经声明 -dNOCACHE 在将来的版本中可能不会出现。
$ b <注意: 生成的PDF很可能会比原来的大。另外,没有额外的命令行参数,原始PDF中的所有图像也可能会根据Ghostscript内置默认值进行处理。这可能会导致不必要的副作用。这些副作用可以通过添加更多的命令行参数来避免。否则。




Ghostscript版本9.15或更新版本
$ b $ g版本9.15(2014年9月发布)支持一个新的命令行参数:

<$这将导致输出设备<$ c> -dNoOutputFonts

$ c> pdfwrite , ps2write eps2write to flatten'glyphs进入基本标记操作(而不是将字体写入输出)。

这意味着:9.15 GS版本之前描述的两个步骤可以避免。使用单个命令可以实现所需的结果:

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


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 to PostScript and back. Also, I would like to use free lightweight cross-platform tools that can be automated from the command line, such as Ghostscript or MuPDF.

解决方案

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.

这篇关于通过将其转换为轮廓形状来替换PDF中的所有字体字形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆