BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Apache FOP 1.0 released

Apache FOP 1.0 released

Leia em Português

This item in japanese

On Wednesday, the Apache Foundation announced the release of Apache FOP 1.0, a project that has been a decade in the making. Apache FOP, or Formatting Objects Processor, started off its life in the XML project at Apache before moving (together with Batik, a Java-based SVG renderer) to the XMLGraphics project back in 2004.

Apache FOP provides a means to turn XML documents into a variety of print-ready formats, such as PDF, PNG or even to others like HTML. Its history goes back to the first release of XSL from the W3C. Although most will conflate XSL with that of the XSL Transformation language itself, XSL was created primarily for the benefit of and by the publishing industry. As a result, the XSL specification covers both the language (eXtensible Stylesheet Language) and also the XSL Formatting Objects specification. From the XSL abstract:

This specification defines the features and syntax for the Extensible Stylesheet Language (XSL), a language for expressing stylesheets. It consists of two parts:

  1. a language for transforming XML documents (XSLT), and
  2. an XML vocabulary for specifying formatting semantics.

What most will think of as XSL is actually XSLT, the first part of the specification. The XSL specification also defines a mini language for defining how print text should be laid out in the form of XSL Formatting Objects, or just FO, in the same specification. (It's this name which gives rise to the Apache FO Processor, and thus the name of the project itself.)

Although CSS 1 was released in 1996, and CSS 2 was released in 1998, neither of them had the ability to work with some print-fidelity requirements such as footnotes, page number references, separating flow of columnar text (i.e. automatically flowing the text across a number of columns, instead of pre-splitting them into separate DIVs). When XSL FO was release in 2001 as part of the XSL specification, there were few processors available to be able to process them. Apache FOP was one of the first, but seemed to stall at version 0.20 (released in 2003) until the reboot at FOP 0.93 (released in 2007). In fact, this split was used to demonstrate OSGi's capability of loading different versions of JARs at an OSGi JSIG event at Sun a few years ago.

An example FO document looks like traditional XML, with an fo namespace, bound to http://www.w3.org/1999/XSL/Format. Here's an example from http://www.renderx.com/tutorial.html (a commercial FO processor):

<?xml version="1.0" encoding="iso-8859-1"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="my-page">
      <fo:region-body margin="1in"/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="my-page">
    <fo:flow flow-name="xsl-region-body">
      <fo:block>Hello, world!</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>

The content in fo:layout contains the style (such as what the page margins are, whether page numbers should be shown and so forth; it supports multiple styles, so you can have separate 'main page' and 'index pages' styles), followed by the fo:page-sequence, which would correspond to that set of pages (e.g. a chapter). Inside, the flow and block are similar to HTML's div and p settings.

Whist it may appear verbose, this is often an intermediary format from something like a MediaWiki or WikiText format. (Eclipse WikiText can be translated into DocBook or XSL-FO already; in fact, a number of DocBook processors generate XSL-FO, which in turn, can be compiled into PDF via tools like Apache FOP.) Maven's site target used Apache FOP to be able to generate PDF versions of the site with the pdf plugin.

Apache FOP 1.0 is not yet fully compliant with the XSL FO specification; a compliance page lists more information about what is supported at the current time.

Rate this Article

Adoption
Style

BT