2006-07-09

让FOP生成支持多语言的pdf文件

在使用fop 0.20.5生成pdf文件,当fo文件里出现不在base-14里的字符时,这些字符在生成的pdf文件里就变成了#符号,看了一下FOP的FAQ,发现原来是FOP里默认的字体不支持Unicode的原因。在windows上有个字体Arial Unicode MS是支持Unicode,于是执行下面的命令为这个字体生成metric file。

B:\bin\fop-0.20.5>java -cp build\fop.jar;lib\avalon-framework.jar;lib\xml-apis.jar;lib\xercesImpl.jar;lib\xalan.jar org.apache.fop.fonts.apps.TTFReader C:\windows\fonts\ARIALUNI.TTF ttfarialuni.xml
TTF Reader v1.1.1
Reading C:\windows\fonts\ARIALUNI.TTF...
Number of glyphs in font: 50377
Postscript format 3
Creating xml font file...
Creating CID encoded metrics
Writing xml font file ttfarialuni.xml...
This font contains no embedding license restrictions


然后在fop目录下的conf文件夹里userconfig.xml里添加下面内容:
<font metrics-file="B:\bin\fop-0.20.5\conf\ttfarialuni.xml" embed-file="C:\windows\fonts\ARIALUNI.TTF" kerning="yes">
<font-triplet name="Arial Unicode MS" style="normal" weight="normal"/>
<font-triplet name="Arial Unicode MS" style="normal" weight="bold"/>
<font-triplet name="Arial Unicode MS" style="italic" weight="normal"/>
<font-triplet name="Arial Unicode MS" style="italic" weight="bold"/>
</font>

这样生成的pdf文件就能正确显示各种语言的字符了。
C:\USER>fop.bat -c B:\bin\fop-0.20.5\conf\userconfig.xml -xml 1.xml -xsl 1.xslt -pdf 1.pdf
[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser
[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser
[INFO] FOP 0.20.5
[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser
[INFO] building formatting object tree
[INFO] setting up fonts
[INFO] [1]
[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser
[INFO] Parsing of document complete, stopping renderer

没有评论:

发表评论