Apache XML FOP

the Apache XML site
 
   

Adding an Extension to FOP

printer
print-friendly
PDF

Overview

For documentation of standard FOP extensions, see the User FOP Extensions document.

If the default funtionality of FOP needs to be extended for some reason then you can write an extension.

There are three types of extensions possible:

  • An output document extension such as the PDF bookmarks
  • an instream-foreign-object extensions such as SVG
  • an fo extension that creates an area in the area tree where normal xsl:fo is not possible

Adding Your Own

To add your own extension you need to do the following things.

  1. Write code that implements your extension functionality. The easiest place to start is by looking at the code in org.apache.fop.extension, and by looking at the examples in the contrib directory.
  2. Create a class that implements the org.apache.fop.fo.ElementMapping interface. ElementMapping is a hashmap of all of the elements in a particular namespace, which makes it easier for FOP to create a different object for each element. ElementMapping objects are static to save on memory. They are loaded by FOP when parsing starts to validate input.
  3. Create the following file: "/META-INF/services/org.apache.fop.fo.ElementMapping", which should contain the fully qualified classname of your ElementMapping implementation class.
  4. Create a jar file containing all of the above files.
  5. Create your XSL-FO file with the extra XML data embedded in the file with the correct name space. The examples for SVG and pdfoutline.fo show how this can be done. The pdf documents on the FOP site use this extension. See also Examples for more examples.
  6. Put your jar file in the classpath
  7. Run FOP using your XSL-FO file as input.