如何添加CIDFont这样的字体名称包含汉字?

时间:2019-12-10 09:59:48

标签: pdf fonts ghostscript

我的Pdf文件中有很多不同的字体,例如方正细等线简体,方正黑体_GBK等。因此,当我使用命令gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dPDFSTOPONERROR -dNOOUTERSAVE -dPDFSETTINGS=/prepress -dCompressFonts=true -dSubsetFonts=false -dEmbedAllFonts=true -sColorConversionStrategy=RGB -dCompatibilityLevel=1.6 -sOutputFile=output.pdf 1000027661706311repair1.pdf将pdf转换为其他格式时,它将运行并报告错误。 :

Processing pages 1 through 3.
Page 1
Can't find CID font "方正黑体_GBK".
Attempting to substitute CID font /Adobe-GB1 for /方正黑体_GBK, see doc/Use.htm#CIDFontSubstitution.
The substitute CID font "Adobe-GB1" is not provided either. attempting to use fallback CIDFont.See doc/Use.htm#CIDFontSubstitution.
Loading a TT font from /usr/local/share/ghostscript/9.50/Resource/CIDFSubst/DroidSansFallback.ttf to emulate a CID font Adobe-GB1 ... Done.
Can't find CID font "方正细等线简体".
Attempting to substitute CID font /Adobe-GB1 for /方正细等线简体, see doc/Use.htm#CIDFontSubstitution.
Can't find CID font "楷体_GB2312".
Attempting to substitute CID font /Adobe-GB1 for /楷体_GB2312, see doc/Use.htm#CIDFontSubstitution.
Loading NimbusRoman-Regular font from /usr/local/share/ghostscript/9.50/Resource/Font/NimbusRoman-Regular... 9497580 8102504 3768888 2094014 3 done.
Page 2
Can't find CID font "方正黑体_GBK".
Attempting to substitute CID font /Adobe-GB1 for /方正黑体_GBK, see doc/Use.htm#CIDFontSubstitution.
Loading a TT font from /usr/local/share/ghostscript/9.50/Resource/CIDFSubst/DroidSansFallback.ttf to emulate a CID font Adobe-GB1 ... Done.
Can't find CID font "方正细等线简体".
Attempting to substitute CID font /Adobe-GB1 for /方正细等线简体, see doc/Use.htm#CIDFontSubstitution.
Page 3
Can't find CID font "方正细等线简体".
Attempting to substitute CID font /Adobe-GB1 for /方正细等线简体, see doc/Use.htm#CIDFontSubstitution.
Loading a TT font from /usr/local/share/ghostscript/9.50/Resource/CIDFSubst/DroidSansFallback.ttf to emulate a CID font Adobe-GB1 ... Done.
Can't find CID font "方正黑体_GBK".
Attempting to substitute CID font /Adobe-GB1 for /方正黑体_GBK, see doc/Use.htm#CIDFontSubstitution.
Can't find CID font "楷体_GB2312".
Attempting to substitute CID font /Adobe-GB1 for /楷体_GB2312, see doc/Use.htm#CIDFontSubstitution.

这是我的/usr/local/share/ghostscript/9.50/Resource/CIDFSubet文件夹:

-rw-r--r-- 1 root root 23M 12月 12 09:17 DroidSansFallback.ttf
lrwxrwxrwx 1 root root  35 12月 11 10:19 FZBSK.TTF -> /usr/share/fonts/winfonts/FZBSK.TTF
lrwxrwxrwx 1 root root  36 12月 11 10:19 FZDBSK.TTF -> /usr/share/fonts/winfonts/FZDBSK.TTF
lrwxrwxrwx 1 root root  35 12月 11 10:19 FZHTK.TTF -> /usr/share/fonts/winfonts/FZHTK.TTF
lrwxrwxrwx 1 root root  35 12月 11 10:19 FZSSK.TTF -> /usr/share/fonts/winfonts/FZSSK.TTF
lrwxrwxrwx 1 root root  36 12月 11 10:19 FZXBSK.TTF -> /usr/share/fonts/winfonts/FZXBSK.TTF
lrwxrwxrwx 1 root root  37 12月 11 10:17 FZXDXJW.TTF -> /usr/share/fonts/winfonts/FZXDXJW.TTF
lrwxrwxrwx 1 root root  42 12月 11 10:19 KaiTi_GB2312.ttf -> /usr/share/fonts/winfonts/KaiTi_GB2312.ttf
lrwxrwxrwx 1 root root  36 12月 11 10:19 msyhbd.ttc -> /usr/share/fonts/winfonts/msyhbd.ttc
lrwxrwxrwx 1 root root  35 12月 11 10:19 msyhl.ttc -> /usr/share/fonts/winfonts/msyhl.ttc
lrwxrwxrwx 1 root root  34 12月 11 10:19 msyh.ttc -> /usr/share/fonts/winfonts/msyh.ttc
lrwxrwxrwx 1 root root  37 12月 11 10:19 simfang.ttf -> /usr/share/fonts/winfonts/simfang.ttf
lrwxrwxrwx 1 root root  36 12月 11 10:19 simhei.ttf -> /usr/share/fonts/winfonts/simhei.ttf
lrwxrwxrwx 1 root root  36 12月 11 10:19 simkai.ttf -> /usr/share/fonts/winfonts/simkai.ttf
lrwxrwxrwx 1 root root  36 12月 11 10:19 simsun.ttc -> /usr/share/fonts/winfonts/simsun.ttc
lrwxrwxrwx 1 root root  36 12月 11 10:19 simyou.ttf -> /usr/share/fonts/winfonts/SIMYOU.TTF
lrwxrwxrwx 1 root root  42 12月 11 10:19 wqy-zenhei.ttc -> /usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc

这是我的/usr/local/share/ghostscript/9.50/Resource/Init/cidfmap.local

...
/MicrosoftYaHei << /FileType /TrueType
  /Path pssystemparams /GenericResourceDir get
  (CIDFSubst/msyh.ttc) concatstrings
  /SubfontID 0
  /CSI [(GB1) 5] >> ;
/MicrosoftYaHei-Bold << /FileType /TrueType
  /Path pssystemparams /GenericResourceDir get
  (CIDFSubst/msyhbd.ttc) concatstrings
  /SubfontID 0
  /CSI [(GB1) 5] >> ;
/MicrosoftYaHeiLight << /FileType /TrueType
  /Path pssystemparams /GenericResourceDir get
  (CIDFSubst/msyhl.ttc) concatstrings
  /SubfontID 0
  /CSI [(GB1) 5] >> ;
/NSimSun << /FileType /TrueType
  /Path pssystemparams /GenericResourceDir get
  (CIDFSubst/simsun.ttc) concatstrings
  /SubfontID 1
  /CSI [(GB1) 5] >> ;
/SimHei << /FileType /TrueType
  /Path pssystemparams /GenericResourceDir get
  (CIDFSubst/simhei.ttf) concatstrings
  /CSI [(GB1) 5] >> ;
/SimSun << /FileType /TrueType
  /Path pssystemparams /GenericResourceDir get
  (CIDFSubst/simsun.ttc) concatstrings
  /SubfontID 0
  /CSI [(GB1) 5] >> ;
...

我知道这个pdf需要一些带有中文字符的字体,但是ghostscript的配置文件是ascii文本,它不支持将其写成中文... 使用iText获取pdf的元数据时,我注意到一些有趣的事情,中文字体名称变为以下格式:

fontTemp = /#bf#ac#cc#e5_GB2312
fontTemp = /#b7#bd#d5#fd#ba#da#cc#e5_GBK
fontTemp = /#b7#bd#d5#fd#cf#b8#b5#c8#cf#df#bc#f2#cc#e5
fontTemp = /STSong-Light

有人知道如何用中文字符添加CIDFont吗?

1 个答案:

答案 0 :(得分:0)

PDF / A规范要求嵌入所有字体(实际上,所有CIDFonts都应该嵌入在PDF文件中)。您似乎根本没有向Ghostscript提供缺少的CIDFont,或者,如果您已将其添加到Ghostscript字体列表中,则没有说明要添加的内容。

您需要创建一个cidfmap文件(可以在ghostpdl / Resource / Init中使用该文件),并使用-I开关包含包含该文件的目录。最简单的解决方案是修改ghostpdl / Resource / Init中的一个,然后在命令行中添加-I / ghostpdl / Resource / Init。

显然,您添加的条目将需要正确获取丢失的字体文件的文件名。几乎可以肯定,您还必须使用PostScript来创建名称,因为您将不得不使用二进制数据,其中可能包括0x20或0x00字符代码。

类似的东西:

<B9656B63C67E497BBF7E807B534F> cvn << ....>> ;