Templates for PDF Documents

Generating PDF documents is a two stage process. It is perhaps easiest to describe the process in reverse order.

PDF documents are generated from documents marked up with XSL-FO in a process called rendering. The document contains the data that should appear in the document (text, figures, etc.) and the XSL-FO mark-up needed to define how this data should be laid out (margins, paper-size, fonts, line-spacing, location of paragraphs, etc.) This rendering stage is handled by the Apache FOP library.

To prepare an XSL-FO document for rendering, the raw data is supplied in an XML document and a template uses XSLT to combine this raw data with the XSL-FO mark-up and the other static elements of the document. In essence, the XSLT inserts the raw data into the template creating the XSL-FO document. This transformation stage is handled by the Apache Xalan library.

Thus, templates for rendering documents as PDF are largely XSL-FO documents with elements of XSLT used to insert values from the XML document at the appropriate point. An example of such a template is given in the next section.