FOP 0.93 improves PDF from XML !

After nearly 3.5 years, the Apache Foundation has released a stable update to their FOP software. This is great news for people using this free java program to convert XML to PDF files. More information and the download can be found at http://xmlgraphics.apache.org/fop/ Among the many changes and fixes are the following.

  • support for the use of Open Type fonts

  • support for SVG in fo:instream-foreign objects for RTF output

  • support for PDF/A-1b and PDF/X-3:2003

  • support for kerning

  • support for XMP metadata

  • lots of bug fixes

  • including a complete redesign of the FOP codebase


I did have some problems following their instructions to install my own fonts. Here is what I finally did after copying the fonts I wanted to the FOP directory. NOTE, with this release you can skip step one and go straight to step 2 if you are using a TTF font.

  1. Correct font conversion process after copying the font files "something.ttf" to the directory where FOP is located.
    C:\downloads\fop-0.93>java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar; lib\commons-logging-1.0.4.jar; lib\commons-io-1.1.jar org.apache.fop.fonts.apps.TTFReader arial.ttf arial.xml
    TTF Reader for Apache FOP 0.93Parsing font...
    Reading arial.ttf...
    Number of glyphs in font: 1674
    3 cmap tables
    CMAP format: 4
    Creating xml font file...
    Creating CID encoded metrics...
    Writing xml font file arial.xml...
    This font contains no embedding license restrictions.XML font metrics file successfully created.

  2. Uncomment this in the userconfig.xml file in the fop directory "conf"; if you are using a TTF font you can also delete the "font metrics-url=" portion for each font as this will be generated automatically.
    <font metrics-url="arial.xml" kerning="yes" embed-url="arial.ttf">
    <font-triplet name="Arial" style="normal" weight="normal"/>
    <font-triplet name="ArialMT" style="normal" weight="normal"/>
    </font>
    <font kerning="yes" embed-url="arial.ttf">
    <font-triplet name="Arial" style="normal" weight="normal"/>
    <font-triplet name="ArialMT" style="normal" weight="normal"/>
    </font>

  3. In the fonts.fo file located in the fop directory/examples/fo/basic, wherever you see font-family="Helvetica" change it to font-family="Arial".

  4. C:\downloads\fop-0.93>fop -c conf/userconfig.xml C:\downloads\fop-0.93\examples\fo\basic\fonts.fo fonts2.pdf


Now there is finally a new stable release to export my docbook xml files with. If only they could get the floats feature working. PS, I have a package of tools for working with fop and xml docbook on Windows if anyone is interested.

Making pdf links with fop and docbook

Wow, all weekend I tried to get any PDF links using FOP 20.5 XSL Stylesheets 1.69 and olink (I needed olink since I had broken my book into chapter.xml files). Links to within the same .xml orignal file worked but as soon as I tried to cross link to another section... no link.

All I wanted was clickable cross links in my PDF to other sections in a PDF document. It works great when you have one single XML document and link things with xref and link but as soon as you try and get fancy and break out the chapters into their own chapter.xml files and then put them together as a book things get nightmarish.

Once I had broken everything up into their own XML files I saw that my xrefs and links were not working any more, at least when they referred to something in one of the other files. Of course everything worked great with RenderX's XEP but that is expensive and I needed something in a free processor like Apache's FOP.

The best I could get was this error "FO processing failed: internal-destination or external-destination must be specified in basic-link" and that was after discovering I needed olinks and needed to make a text file to describe where the links were kept (olinkdb.xml). Ugh, what a pain.

Of course I had the syntax for that olinkdb.xml file all messed up and couldn't understand the whole olink idea to begin with. Finally I got the olinkdb file right... with some tests using RenderX's XEP Personal edition. Then thanks to Google I came across this newsgroup comment from 2 weeks ago and everything started to fall into place: HERE .

So, following Robert's suggestion to turn off insert.xref.page.number I suddenly found my olinks appearing Happy. No page numbers or named destinations but at least there are links. RenderX works great with this insert.xref.page.number activated but FOP just choked unless it was off.

Here is a summary of what I did. Note any directory paths to be sure files are in the right place.
  1. make a customization xsl file with the following parameters:

    < xsl :param name="fop.extensions" select="1"/>
    < xsl :param name="insert.xref.page.number" select="0"/>
    < xsl :param name="targets.filename" select="'C:/documents/targets.db'">
    < xsl :param name="target.database.document" select="'file:/C:/documents/olinkdb.xml'">
    < xsl :param name="collect.xref.targets" select="'yes'">
    < xsl :param name="current.docid" select="'testbook'">
    < xsl :param name="prefer.internal.olink" select="1">
    < xsl :param name="insert.olink.pdf.frag" select="1">



  2. Make an olinkdb.xml file (the targets.db will be autogenerated) like below
    < ?xml version="1.0"?>
    < !DOCTYPE targetset SYSTEM "file:/C:/docbook-xsl-1.69.0/common/targetdatabase.dtd" [
    < !ENTITY book-targets SYSTEM "file:/C:/documents/targets.db">
    ]>
    < targetset>
    < targetsetinfo> Description of this target database document,
    which is for the examples in olink doc. < /targetsetinfo>

    < document targetdoc="testbook">&book-targets;< /document>
    < /targetset>




  3. Put my olinks in with only the targetptr set to the linkend name of someplace in one of the documents (without any targetdoc). These olinks could either be with preset text or empty (and becoming autofilled later.) NOTE - the auto filling seemed to have some problems if the linkends were placed on a title. All should be fine if linkends stay on sections and chapters.



  4. compile my pdf from the main book.xml.



Sorry if some of the above texts did not come out right. I'll try to clean them up again later. As I said, ugh.