Tutorial introduction and preparation
The XSL Formatting Objects specification, an official recommendation of the W3C that's commonly known as XSL-FO, defines a number of XML tags that describe how something should be rendered. Although XSL-FO contains elements that describe how to render text in nonprint formats such as spoken text, this tutorial introduces how to create portable document format (PDF) files -- the most common use of XSL-FO.
The tutorial takes up where the "XSL Formatting Objects basics" tutorial left off. It covers in detail the formatting of lists, tables, and cross references. The tutorial goes on to demonstrate how to create complex documents with multiple layouts and repeating elements, such as running heads, on the pages. You'll also find out how to create PDF bookmarks and a table of contents. Finally the tutorial shows how to convert HTML elements to formatting objects and then to PDF format. Downloadable code samples make it easy to adapt samples for your own needs.
The code listings in Resources contain a complete XSLT style sheet that converts an XHTML document into a file of formatting objects.
When you've completed this pair of tutorials, you'll be ready to create your own XML applications that use formatting objects to generate high-quality printable documents.
What you need to know already to benefit from this tutorial
This tutorial assumes that you already comprehend the Extensible Markup Language (XML) and know how to work with it and its related technologies, such as XML Stylesheet Language-Transformation (XSLT). It also assumes that you understand the basic structure of XSL-FO documents, how it functions, how to set up page definitions and text specification, add graphics, and control page and column breaks. If you need to brush up your understanding of XSL-FO fundamentals, start with the prequel to this tutorial, " XSL Formatting Objects basics."
The tools used for the examples are written in Java code, but you don't have to understand the Java language to use them.
What you need to know about the software and standards
Figure 1. FOP project logo
Although you can use other XSL-FO rendering engines, this tutorial is written for the Apache XML Project's FOP (Formatting Objects to PDF) translator. The examples in this tutorial work with FOP Version 0.20.4, which was released on July 5, 2002. If you try them with other versions of FOP, they may or may not work. The XSL-FO spec became an official recommendation of the W3C on 15 October 2001; the FOP tool supports most of the final spec.
We use the FOP tool at developerWorks for two reasons:
- It's written in the Java language, and so it runs on all the platforms we care about.
- It's a no-cost, open-source product, and so anyone can afford it.
If you want to immerse yourself in XSL-FO, you can go directly to the source for the spec at the W3C's site (see Resources). Be aware that this is one of the longest documents at the W3C (roughly 400 pages), although most of it is reference information for the many elements and attributes in the XSL-FO tag set. The reference sections -- particularly Appendixes B, C, and D -- are very useful for looking up property names and values. Remember, as of this writing, FOP does not completely support the XSL-FO spec, and so certain property names and values defined by the spec might not be supported by the tool, or they might be supported with slightly different names and values.
What tools you'll need for the tutorial and how to configure them
To go through the exercises in this tutorial, you'll need to have a Java Developer's Kit (JDK) Version 1.3 or later, as well as the FOP package from the Apache XML Project. You can get the FOP package. Download the latest version and unzip it.
Once you have the JDK and FOP installed, you need to set the classpath.
If you want to follow the examples in the tutorial without remembering to adapt them, put the FOP package at c:\fop-0.20.4rc and then set the classpath like this (except all on one line, of course; I've broken the line only to fit within the text column here):
set classpath=.;c:\fop-0.20.4rc\build\fop.jar;c:\fop-0.20.4rc\ lib\avalon-framework-cvs-20020315.jar;c:\fop-0.20.4rc\lib\bati k.jar;c:\fop-0.20.4rc\lib\xalan-2.3.1.jar;c:\fop-0.20.4rc\lib\ xercesImpl-2.0.1.jar;c:\fop-0.20.4rc\lib\xml-apis.jar; |
If you unzip the FOP package somewhere else, you'll need to change the command accordingly. If you're running Linux, use the command export classpath=/usr/bin/fop-0.20.4rc/build/fop.jar:/usr/bin/fop-... and so on.


