Apache™ FOP Design: PDF Library
Introduction
The PDF Library is an independant package of classes in Apache™ FOP. These class provide a simple way to construct documents and add the contents. The classes are found in org.apache.fop.pdf.*.
PDF Document
This is where most of the document is created and put together.
It sets up the header, trailer and resources. Each page is made and added to the document. There are a number of methods that can be used to create/add certain PDF objects to the document.
Building PDF
The PDF Document is built by creating a page for each page in the Area Tree.
This page then has all the contents added. The page is then added to the document and available objects can be written to the output stream.
The contents of the page are things such as text, lines, images etc. The PDFRenderer inserts the text directly into a pdf stream. The text consists of markup to set fonts, set text position and add text.
Most of the simple pdf markup is inserted directly into a pdf stream. Other more complex objects or commonly used objects are added through java classes. Some pdf objects such as an image consists of two parts.
It has a separate object for the image data and another bit of markup to display the image in a certain position on the page.
The java objects that represent a pdf object implement a method that returns the markup for inserting into a stream. The method is: byte[] toPDF().
Features
Fonts
Support for embedding fonts and using the default Acrobat fonts.
Images
Images can be inserted into a page. The image can either be inserted as a pixel map or directly insert a jpeg image.
Stream Filters
A number of filters are available to encode the pdf streams. These filters can compress the data or change it such as converting to hex.
Links
A pdf link can be added for an area on the page. This link can then point to an external destination or a position on any page in the document.
Patterns
The fill and stroke of graphical objects can be set with a colour, pattern or gradient.
The are a number of other features for handling pdf markup relevent to creating PDF files for FOP.