中文docbook转换成PDF终于实现
终于搞定了~~~
- 首先安装fop
据说fop对中文的断行支持得比0.93好。另外"zh_cn"也可以正确处理了。
# emerge fop -av
- 然后生成字体描述文件
TTF Reader for Apache FOP 0.94
Parsing font...
Reading /usr/share/fonts/fireflysung/fireflysung.ttf...
Font Family: AR PL New Sung
Creating xml font file...
Creating CID encoded metrics...
Writing xml font file fireflysung.xml...
This font contains no embedding license restrictions.
XML font metrics file successfully created.
# java -cp /usr/share/fop/lib/fop.jar:/usr/share/avalon-framework
-4.2/lib/avalon-framework.jar:/usr/share/commons-logging/lib/commons-logging.jar:/usr/share/commons-io-1/lib/commons-io.jar org.apache.fop.fonts.apps.TTFReader -ttcname "SimSun" /usr/share/fonts/winfonts/simsun.ttf simsun.xml
TTF Reader for Apache FOP 0.94
Parsing font...
Reading /usr/share/fonts/winfonts/simsun.ttf...
This is a TrueType collection file with 2 fonts
Containing the following fonts:
SimSun <-- selected
NSimSun
Font Family: SimSun
Creating xml font file...
Creating CID encoded metrics...
Writing xml font file simsun.xml...
This font contains no embedding license restrictions.
XML font metrics file successfully created.
# mkdir /etc/fop
# mv *.xml /etc/fop
- 建立FOP配置文件
# cd /etc/fop
建立zhfop.conf的内容如下:
.
flate
embed-url="/usr/share/fonts/winfonts/simsun.ttf">
- 创建xsl文件
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
exclude-result-prefixes="doc"
version="1.0">
- 用xsltproc来生成HTML或者XSL-FO文件
譬如,下面是根据Docbook文档生成HTML的例子:
$ xsltproc --output myfile.html /usr/share/sgml/docbook/xsl-stylesheets/html/docbook.xsl myfile.xml
或者根据docbook文档生成XSL-FO文档的例子:
$ xsltproc --output /usr/share/sgml/docbook/xsl-stylesheets/fo/docbook.xsl myfile.xml
- 用fop生成PDF文档