Creating a Formatted Document

To process ch14_03.po and create a formatted document, I'll use James Tauber's FOP (Formatting Objects Processor), which has now been donated to the Apache XML Project. (The alphaWorks XML for Java parsers that I've been using for several chapters are based on the Apache XML project's Xerces XML parser.)

Here's how the Apache XML Project describes FOP:

FOP (Formatting Objects Processor) is the world's first print formatter driven by XSL formatting objects and the world's first output independent formatter. It is a Java application that reads a formatting object tree and then renders the resulting pages to a specified output. Output formats currently supported are PDF, PCL, PS, SVG, XML (area tree representation), Print, AWT, MIF, and TXT. The primary output target is PDF.

Here's how the objectives of FOP are described:

The goals of the Apache XML FOP Project are to deliver an XSL FOPDF formatter that is compliant to at least the Basic conformance level described in the 27 March 2000 XSL WD (W3C Working Draft) and that complies with the 11 March 1999 Portable Document Format Specification (Version 1.3) from Adobe Systems.

You can get FOP at http://xml.apache.org/fop; just click the Download button to download it. The FOP package, including documentation, comes zipped , so you have to unzip it. The current version as of this writing is 0.20.4 and it's written in Java; the compressed file that you download is fop-0.20.4-bin.tar.gz (even though it's a .tar.gz file, even Windows unzip utilities, such as WinZip, can unzip it). To convert ch14_03.fo into a PDF file, ch14_04.pdf, you can navigate to the fop-0.20.4 directory created when you unzip fop-0.20.4-bin.tar.gz and enter this command (this assumes that ch14_03.fo is in the fop-0.20.4 directory also):

 %java -cp build\fop.jar;lib\batik.jar;lib\xalan-2.3.1.jar;lib\xercesImpl-2.0.1.jar;lib\ graphics/ccc.gif xml-apis.jar;lib\avalon-framework-cvs-20020315.jar;lib\logkit-1.0.jar;lib\jimi-1.0.jar graphics/ccc.gif org.apache.fop.apps.Fop ch14_03.fo ch14_04.pdf 

That's quite a mouthful, so FOP comes with a script for most shells , including a .bat file for Windows. This means that you only have to enter this command in the fop-0.20.4 directory to do the same thing:

 %fop ch14_03.fo ch14_04.pdf 

And that's it. You can see the final results, ch14_04.pdf, in the Adobe Acrobat PDF reader (which you can get for free at www.adobe.com/products/acrobat/readermain.htmlcurrently, the download process starts at www.adobe.com/products/acrobat/readstep.html) in Figure 14-1. The ch14_01.xml document appears in that figure formatted exactly as it should be. The PDF format is a good one for formatting object output, although it has some limitations. For example, it can't handle dynamic tables that can expand or collapse at the click of a mouse, or interactive multiple-target links, both of which are part of the formatting objects specification.

Figure 14-1. A PDF document created with formatting objects.

graphics/14fig01.gif

Now you've seen how the process works; it's time to get to the details, starting with an overview.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net