通过将 PDF 中的所有字体字形转换为轮廓形状来替换它们 [英] Replace all font glyphs in a PDF by converting them to outline shapes
问题描述
我正在寻找一种方法来勾勒" PDF 文件中的所有文本/字体,即将它们转换为曲线.
I am looking for a way to 'outline' all text/fonts in a PDF file, i.e. convert them to curves.
我更愿意这样做而不必将 PDF 转换为 PostScript 并返回.另外,我想使用可以从命令行自动执行的免费轻量级跨平台工具,例如 Ghostscript 或 MuPDF.
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.
推荐答案
是的,您可以使用 Ghostscript 来实现您想要的.
Yes, you can use Ghostscript to achieve what you want.
您需要经过 2 个步骤:
You need to go through 2 steps:
将 PDF 转换为 PostScript 文件,但使用一个相对未知的参数的副作用:它被称为
-dNOCACHE
.这会将所有使用的字体转换为轮廓形状:
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
将 PS 转换回 PDF(并且,可能再次删除中间 PS):
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
此方法长期不可靠,因为 Ghostscript 开发人员已声明 -dNOCACHE
可能不会出现在未来版本中.
This method is not reliable long-term, because the Ghostscript developers have stated that -dNOCACHE
may not be present in future versions.
注意:生成的 PDF 很可能比原始 PDF 大.另外,如果没有额外的命令行参数,原始 PDF 中的所有图像也可能会根据 Ghostscript 内置默认值进行处理.这可能会导致不必要的副作用.可以通过添加更多命令行参数来避免这些副作用.
Ghostscript 9.15 版(2014 年 9 月发布)支持新的命令行参数:
Ghostscript version 9.15 (released in September 2014) supports a new command line parameter:
-dNoOutputFonts
这将导致输出设备 pdfwrite
、ps2write
和 eps2write
将字形展平"为基本"标记操作(而不是将字体写入输出)".
This will cause the output devices pdfwrite
, ps2write
and eps2write
"to 'flatten' glyphs into 'basic' marking operations (rather than writing fonts to the output)".
这意味着:可以避免针对 9.15 GS 之前版本描述的两个步骤.只需一个命令即可获得所需的结果:
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
注意: 与第一部分中已经提到的相同的警告是正确的.如果您的 PDF 包含图像,则可能存在由简单的上面的命令行.为避免这些,您需要添加更多特定参数.
这篇关于通过将 PDF 中的所有字体字形转换为轮廓形状来替换它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!