如果你在一个指令窗口中运行上述指令文件,得到下面的结果: [pre] run_fop USAGE Fop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-pcl|-ps |-txt|-at|-print] <outfile> [OPTIONS] -d debug mode -x dump configuration settings -q quiet mode -c cfg.xml use additional configuration file cfg.xml -l lang the language to use for user information -s for area tree XML, down to block areas only ... [/pre] 你的安装便是成功的。
根据使用说明,FOP 有两个主要功能:
- 将 XSL-FO 文件排版生成 .txt,.pdf,或者 .ps 文件。
- 按照 XSLT 文件所给转换和排版语句,将 XML 文件转换并排版生成 .txt,.pdf,或者 .ps 文件。
将 XSL-FO 文件排版生成 .txt 文件 --------
首先让我们作一个简单的例子,将 hello.fo 排版生成一个 .txt 文件。请运行下面的指令: [pre] run_fop -fo hello.fo -txt hello.txt [/pre] 你会得到如下的信息: [pre] [INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser [INFO] FOP 0.20.5rc2 [INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser [INFO] building formatting object tree [INFO] setting up fonts [INFO] rendering areas to TEXT [INFO] [1] [INFO] Parsing of document complete, stopping renderer [INFO] writing out TEXT [/pre] 从这些信息中,我们可以看出,FOP 使用了 Xerces SAXParser 来阅读 XSL-FO 文件。我们 还可以看出,排版后的结果只有一页。
为了验证结果,请将 hello.txt 文件用 notepad 打开,你会看到: [pre]
Hello world!
... [/pre] 排版结果完全正确。
将 XSL-FO 文件排版生成 .pdf 文件 --------
我们的第二个例子是将 hello.fo 排版生成一个 .pdf 文件。请运行下面的指令: [pre] run_fop -fo hello.fo -pdf hello.pdf [/pre] 你会得到如下的信息: [pre] [INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser [INFO] FOP 0.20.5rc2 [INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser [INFO] building formatting object tree [INFO] setting up fonts [INFO] [1] [INFO] Parsing of document complete, stopping renderer [/pre] 然后请用 Adobe Reader 打开 hello.pdf,你会看到“Hello world!”被正确地排版在 页面的左上角。这个结果非常鼓舞人心,我对 FOP 的感觉越来越好了。