以poppler为后端pdf软件乱码解决方案(okular, epdfview, evince...)

来源:岁月联盟 编辑:exp 时间:2012-02-29
注:因为okular, epdfview, evince的pdf功能均由xpdf的分支poppler提供,所以这里以poppler来代称这些软件。kpdf下没有测试过,因为我现在直接用okular。
poppler官方网站:http://poppler.freedesktop.org/
 
和很朋友一样,poppler的乱码是我最不愿意看到的。
后来我看了软件依赖情况,认识到okular等都是以poppler为后端。
poppler的官方有如下说明:
 
http://freedesktop.org/wiki/Software/poppler
 
QUOTE:
Suggested Fontconfig font substitutions
Poppler is using fontconfig to do the font searching on the system for fonts that are not embedded into the pdf files. This is a list of recommended font substitutions that distributions/users should have in their fontconfig configuration
也就是说,poppler从fontconfig的配置文件中读取字体取代pdf里的字体。于是,我们也只需要配好了字体替代就可以了。这一点和openoffice里相似,openoffice除了接受他自己的字体替代外,也接受这种fontconfig的字体替代。
 
如果你已经装了很多windows的字体,基本上你不会有乱码的情况。如果你没有装,就要字体替代了。上文的官方wiki提供了替代的方法,当然前提是你安装了poppler-data,否则还是无法显示中文。
 
下面给出我的配置文件。
 
为所有中文指定一个或几个字体
 
CODE:
<match target="font">
  <test name="lang" equal="any" compare="eq">
    <string>zh</string> <!--指定语言,另外也可以为ja, ko指定-->
  </test>
  <edit name="spacing">
    <const>proportional</const>
  </edit>
  <edit name="globaladvance">
    <bool>false</bool>
  </edit>
  <edit name="family" mode="prepend" binding="strong"><!--这里用的是strong-->
    <string>AR PL ShanHeiSun Uni</string><!--我的中文字体-->
  </edit>
</match>
单独为用楷体情况指定
 
CODE:
<match target="pattern">
  <test name="family">
    <string>KaiTi_GB2312</string>
    <string>STXingkai</string>
    <string>STXinwei</string>
  </test>
  <edit name="family" mode="prepend" binding="same">
    <string>AR PL ZenKai Uni</string>
  </edit>
</match>
当然,我还把我中文字体里的英文换成漂亮的英文字体。
 
更正:kpdf不是以poppler为后端。