【发布时间】:2016-10-18 15:37:55
【问题描述】:
我的 ghostscript 命令是这样的:
gs \
-dBATCH -dNOPAUSE \
-sDEVICE=pdfwrite \
-dColorConversionStrategy=/LeaveColorUnchanged \
-dDownsampleMonoImages=false \
-dDownsampleGrayImages=false \
-dDownsampleColorImages=false \
-dAutoFilterColorImages=false \
-dAutoFilterGrayImages=false \
-dColorImageFilter=/FlateEncode \
-dGrayImageFilter=/FlateEncode \
-sOutputFile=./merge.pdf \
-f ./page_*.pdf
大部分命令都与图像相关。
执行后,我发现字体看起来没有输入文件那么锐利。
字体的区别如下:
输入文件(之一)的字体:
$ pdffonts page_3.pdf
name type encoding emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
NachlieliCLM-Bold Type 1 Builtin yes no yes 62 0
NachlieliCLM-Bold Type 1 Custom yes no yes 65 0
Courier10PitchBT-Bold Type 1 Builtin yes no yes 70 0
EAAAAA+LiberationSerif TrueType WinAnsi yes yes yes 27 0
NachlieliCLM-Light Type 1 Builtin yes no yes 75 0
NachlieliCLM-Light Type 1 Custom yes no yes 78 0
HAAAAA+LiberationSans-Bold TrueType WinAnsi yes yes yes 42 0
IAAAAA+DejaVuSans TrueType WinAnsi yes yes yes 47 0
JAAAAA+LMMono9-Regular Type 1 Builtin yes yes yes 52 0
KAAAAA+LMMonoProp10-Regular Type 1 Builtin yes yes yes 37 0
Courier10PitchBT-Roman Type 1 Builtin yes no yes 83 0
MAAAAA+LiberationSerif-Bold TrueType WinAnsi yes yes yes 57 0
NAAAAA+LiberationSerif-Italic TrueType WinAnsi yes yes yes 32 0
输出文件的字体:
$ pdffonts merge.pdf
name type encoding emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
LQRJGW+LiberationSerif-Bold TrueType WinAnsi yes yes yes 54 0
ZAZOKA+NachlieliCLM-Light Type 1C Custom yes yes yes 42 0
XFXEQZ+LiberationSerif-Italic TrueType WinAnsi yes yes yes 56 0
KBCNYY+LiberationSans-Bold TrueType WinAnsi yes yes yes 44 0
PPEMTT+DejaVuSans TrueType WinAnsi yes yes yes 46 0
FUVLBK+NachlieliCLM-Bold Type 1C Custom yes yes yes 36 0
OQFKGW+LMMono9-Regular Type 1C Custom yes yes no 48 0
ZFATCB+LMMonoProp10-Regular Type 1C Custom yes yes no 50 0
WIGEDL+Courier10PitchBT-Bold Type 1C WinAnsi yes yes no 38 0
AFLCKO+Courier10PitchBT-Roman Type 1C WinAnsi yes yes no 52 0
QNUNTR+LiberationSerif TrueType WinAnsi yes yes yes 40 0
BLSWAW+DejaVuSansMono TrueType WinAnsi yes yes yes 97 0
HQDKJN+LiberationSerif TrueType WinAnsi yes yes yes 99 0
SCAKLE+LiberationSerif-Italic TrueType WinAnsi yes yes yes 101 0
AGALJA+NachlieliCLM-Bold Type 1C Custom yes yes yes 91 0
PPEMTT+DejaVuSans TrueType WinAnsi yes yes yes 103 0
TLVEAY+LiberationSans-Bold TrueType WinAnsi yes yes yes 93 0
GLOKSW+NachlieliCLM-Light Type 1C Custom yes yes yes 95 0
部分起作用的唯一方法是执行以下操作:
gs \
-dBATCH -dNOPAUSE \
-sDEVICE=pdfwrite \
-dCompressFonts=true \
-dSubsetFonts=true \
-dEmbedAllFonts=false \
-sOutputFile=./merge.pdf \
-f ./page_*.pdf
$ pdffonts merge.pdf
name type encoding emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
LQRJGW+LiberationSerif-Bold TrueType WinAnsi yes yes yes 54 0
NachlieliCLM-Light Type 1 Custom no no yes 42 0
XFXEQZ+LiberationSerif-Italic TrueType WinAnsi yes yes yes 56 0
KBCNYY+LiberationSans-Bold TrueType WinAnsi yes yes yes 44 0
PPEMTT+DejaVuSans TrueType WinAnsi yes yes yes 46 0
NachlieliCLM-Bold Type 1 Custom no no yes 36 0
EVJWAP+LMMono9-Regular Type 1C Custom yes yes no 48 0
LAKFSN+LMMonoProp10-Regular Type 1C Custom yes yes no 50 0
Courier10PitchBT-Bold Type 1 WinAnsi no no no 38 0
Courier10PitchBT-Roman Type 1 WinAnsi no no no 52 0
QNUNTR+LiberationSerif TrueType WinAnsi yes yes yes 40 0
BLSWAW+DejaVuSansMono TrueType WinAnsi yes yes yes 97 0
HQDKJN+LiberationSerif TrueType WinAnsi yes yes yes 99 0
SCAKLE+LiberationSerif-Italic TrueType WinAnsi yes yes yes 101 0
NachlieliCLM-Bold Type 1 Custom no no yes 91 0
PPEMTT+DejaVuSans TrueType WinAnsi yes yes yes 103 0
TLVEAY+LiberationSans-Bold TrueType WinAnsi yes yes yes 93 0
NachlieliCLM-Light Type 1 Custom no no yes 95 0
在最后一种情况下 - 字体 LMMono9 没有改变,但字体 NachlieliCLM 更清晰(可能是因为它没有嵌入......)。
正如你所看到的 - 一些字体没有嵌入 - 这很糟糕。
输出 PDF 用于打印和共享,因此需要嵌入高质量的字体。
顺便说一句,我知道标志需要这样:
-dCompressFonts=true \
-dSubsetFonts=false \
-dEmbedAllFonts=true \
但是这些标志的字体仍然不清晰。
我已经阅读了许多 SO 线程和文档,但未能找到解决方案。
我怀疑我需要输出字体为Type 1 类型,而不是Type 1C 类型,但不确定。
示例:
附上两个文件:input.pdf 和 output.pdf。
它们之间的区别仅在以下文本中:
- “标题在这里(标题 2)” - 字体为
Courier 10 Pitch - 从“第一”到“第六”的项目符号 - 字体为
LM Mono 9
(请注意,项目符号中的其余句子很好 - 它不会改变。这意味着只有单词数字,如“First”,是改变的。) - 最后/底部(希伯来语)句子 - 字体为
Nachlieli CLM
不同的是,在输出文件中,文本更粗暴。 (输入更清晰)。为了查看差异,将两个 PDF 文档并排放置,每个文档都有 100% 的缩放。使用 Ubuntu 的默认 Document Viewer 或 Okular 时,差异很明显。
其余文字相同。
实际上,输入 PDF 文件也是使用 LibreOffice 4.2 创建的。
输出文件是使用以下命令创建的:
gs \
-dBATCH -dNOPAUSE \
-sDEVICE=pdfwrite \
-dColorConversionStrategy=/LeaveColorUnchanged \
-dDownsampleMonoImages=false \
-dDownsampleGrayImages=false \
-dDownsampleColorImages=false \
-dAutoFilterColorImages=false \
-dAutoFilterGrayImages=false \
-dColorImageFilter=/FlateEncode \
-dGrayImageFilter=/FlateEncode \
-sOutputFile=./output.pdf \
-f ./input.pdf
我正在使用 GPL Ghostscript 9.10 和 Ubuntu 14.04。
Screenshot 显示输入(前 GS)和输出(后 GS)之间的差异。使用软件Document Viewer 3.10(或Evince)。
【问题讨论】:
-
也许像pdfbox 这样的东西更适合您的需求,只需下载..app.jar 并尝试
java -jar pdfbox-app-2.0.0-RC3.jar PDFMerger ./page_*.pdf merge.pdf
标签: pdf fonts pdf-generation ghostscript