【发布时间】:2012-06-21 00:36:08
【问题描述】:
简而言之,我正在处理一个有问题的 PDF,其中:
- 由于缺少字体信息,无法在
evince等文档查看器中完全呈现; - 但是 -
ghostscript可以完全呈现相同的 PDF。
因此——无论ghostscript 使用什么来填充空白(可能是备用字形,或访问字体的不同方法)——我希望能够使用 @ 987654334@ 生成(“提取”)输出 PDF,其中几乎什么都不会改变,除了添加的字体信息,因此evince 可以以与ghostscript 相同的方式呈现相同的文档能够。
我的问题是这样的——这有可能吗?如果是这样,命令行是什么来实现这样的目标?
非常感谢您的任何回答,
干杯!
详情:
我实际上使用的是较旧的 Ubuntu 10.04,我可能遇到了 - 不是错误 - 而是 evince 的安装问题(缺少 poppler-data 包),如 Bug #386008 “Some fonts fail to display due to “Unknown font tag...” : Bugs : “poppler” package : Ubuntu 中所述。
但是,这正是我想要处理的,所以我将使用该帖子所附的fontspec.pdf ("PDF triggering the bug.", // v .) 来演示问题。
evince
首先,我在evince 中打开此pdf 的第3 页;和evince 抱怨:
$ evince --page-label=3 fontspec.pdf
Error: Missing language pack for 'Adobe-Japan1' mapping
Error: Unknown font tag 'F5.1'
Error (7597): No font in show
Error: Unknown font tag 'F5.1'
Error (7630): No font in show
Error: Unknown font tag 'F5.1'
Error (7660): No font in show
Error: Unknown font tag 'F5.1'
...
渲染效果如下:
... 很明显有些字体形状丢失了。
Adobe acroread
仅说明 Adobe 的 Acrobat Reader for Linux 的行为方式;以下命令行:
$ ./Adobe/Reader9/bin/acroread /a "page=3" fontspec.pdf
... 不会向终端生成任何输出(有关/a 开关的更多信息,请参阅Man page acroread)——而且程序在显示字体方面绝对没有问题。
另外,虽然我想避免往返于 postscript - 但是,请注意 acroread 本身可用于将 PDF 转换为 postscript:
$ ./Adobe/Reader9/bin/acroread -v
9.5.1
$ ./Adobe/Reader9/bin/acroread -toPostScript \
-rotateAndCenter -choosePaperByPDFPageSize \
-start 3 -end 3 \
-level3 -transQuality 5 \
-optimizeForSpeed -saveVM \
fontspec.pdf ./
同样,上面的命令行将不会向终端生成任何输出; -optimizeForSpeed -saveVM 在那里,因为显然它们处理字体;最后一个参数./ 是输出目录(输出文件自动称为fontspec.ps)。
现在,evince 可以在fontspec.ps 输出中显示以前丢失的字体 - 但再次抱怨:
$ evince fontspec.ps
GPL Ghostscript 9.02: Error: Font Renderer Plugin ( FreeType ) return code = -1
GPL Ghostscript 9.02: Error: Font Renderer Plugin ( FreeType ) return code = -1
...
...此外,所有 text 似乎在后记中都被压平为曲线 - 所以现在不能再选择 evince 中的 .ps 文件中的文本了(注意 . ps 文件无法在acroread 中打开)。但是,可以再次将此 .ps 转换回 .pdf:
$ pstopdf fontspec.ps # note, `pstopdf` has no output filename option;
# it will automatically choose 'fontspec.pdf',
# and overwrite previous 'fontspec.pdf' in
# the same directory
...现在pstopdf 输出中的文本可以在evince 中选择,所有字体都在那里,evince 不再抱怨了。但是,正如我所指出的,我想完全避免往返于 postscript 文件。
display(来自imagemagick)
我们也可以使用imagemagicks display 观察同一个文档中的页面(注意image panning from the commandline using 'display' 显然仍然不可用,所以我在下面使用-crop 来调整视口):
$ display -density 150 -crop 740x450+280+200 fontspec.pdf[2]
**** Warning: considering '0000000000 00000 n' as a free entry.
...
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Mac OS X 10.5.4 Quartz PDFContext <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
... 这会产生一些 ghostscripish 错误 - 结果如下:
... 很明显,evince 无法渲染的缺失字体现在显示在这里,imagemagicks display,正确。
ghostscript
最后,我们可以use ghostscript as x11 viewer自己——观察同一个页面,同一个文档:
$ gs -sDevice=x11 -g740x450 -r150x150 -dFirstPage=3 \
-c '<</PageOffset [-120 520]>> setpagedevice' \
-f fontspec.pdf
GPL Ghostscript 9.02 (2011-03-30)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
Processing pages 3 through 74.
Page 3
>>showpage, press <return> to continue<<
^C
...以及此输出的结果:
总结:ghostscript(以及 显然 的扩展名,imagemagick)似乎可以找到丢失的字体(或者至少可以找到它的替代品),并且用它渲染一个页面——即使evince 在同一个文档中失败。
因此,我只想从ghostscript 导出一个PDF 版本,它只会嵌入缺少的字体,没有其他处理;所以我试试这个:
$ gs -dBATCH -dNOPAUSE -dSAFER \
-dEmbedAllFonts -dSubsetFonts=true -dMaxSubsetPct=99 \
-dAutoFilterMonoImages=false \
-dAutoFilterGrayImages=false \
-dAutoFilterColorImages=false \
-dDownsampleColorImages=false \
-dDownsampleGrayImages=false \
-dDownsampleMonoImages=false \
-sDEVICE=pdfwrite \
-dFirstPage=3 -dLastPage=3 \
-sOutputFile=mypg3out.pdf -f fontspec.pdf
GPL Ghostscript 9.02 (2011-03-30)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
**** Warning: considering '0000000000 00000 n' as a free entry.
Processing pages 3 through 3.
Page 3
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Mac OS X 10.5.4 Quartz PDFContext <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
...但它不起作用 - 输出文件 mypg3out.pdf 遇到与前面提到的 evince 完全相同的问题。
注意:虽然我想避免 postscript 往返,但 gs 命令行的一个很好的例子,从 pdf 到 ps 并带有字体嵌入:(#277826) pdf - How to make GhostScript PS2PDF stop subsetting fonts;但 .pdf 到 .pdf 的相同命令行切换似乎对上述问题没有任何影响。
【问题讨论】:
-
呸,棘手的问题。不是我的区域,但 +1 并祝你好运! (我认为您不能从其源应用程序重新创建 PDF?这可能更容易)。
-
非常感谢@halfer 的评论 - 实际上,无法重新创建有问题的 PDF;照原样得到它,并且必须将它也包含在 PDF 集合中
:/。至少,与此同时,我可以确认这是带有 CID/CJK 字体的font mapping problem;所以现在的问题是如何(如果可能)让ghostscript根据“已知”字体映射(不会引发错误)重新映射嵌入的 CID 字体字形。干杯!
标签: pdf fonts ghostscript