Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Creating a Formatted Document

To process planets.fo and create a formatted document, I'll use James Tauber's fop, which has now been donated to the Apache XML Project.

The main fop page is http://xml.apache.org/fop, and currently, you can download fop from http://xml.apache.org/fop/download.html. The fop package, including documentation, comes zipped, so you have to unzip it. It's implemented as a Java JAR file, fop.jar, and I'll use fop version 0.15 here.

You can use fop from the command line with a Java class that at thiswriting is org.apache.fop.apps.CommandLine. You need to provide theXML parser you want to use, and I'll use the Xerces Java parser in xerces.jar (which comes with Xalan). Here's how I use fop to convert planets.fo to planets.pdf with Java in Windows; in this case, I'm specifying the classpath with the -cp switch to include xerces.jar, as well as two necessary JAR files that come with the fop download—fop.jar and w3c.jar. (This example assumes that fop.jar, xerces.jar, and w3c.jar are all in C:\planets—if not, you can specify their full paths.)

C:\planets>java -cp fop.jar;xerces.jar;w3c.jar
_org.apache.fop.apps.CommandLine planets.fo planets.pdf

You can use the Adobe Acrobat PDF reader to see the resulting file, planets. pdf, as shown in Figure 1.8. (You can get Acrobat PDF Reader for free at http://www.adobe.com/products/acrobat/readermain.html.) The planets.xml document appears in that figure formatted as specified in the planetsPDF.xsl stylesheet.

Figure 1.8 A PDF document created with formatting objects.

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. Although there is little support in any major browser for XSL-FO today, it will most likely be supported in browsers one day.

That completes your overview. In this book, you're going to see all there is to XSLT, and you'll also get an introduction to XSL-FO. Now it's time to dig into XSLT, starting with the next chapter.

  • + Share This
  • 🔖 Save To Your Account