Generating XSL-FO Layouts with Microsoft Word and Apache POI
The objective of this post is to describe how to create XSL-FO Layouts with little or no costs! These can then be used for custom PDF documents printing in Oracle Application Express (APEX).
Let's get started...
Tools that you will need:
- Microsoft Word 97 and up.
- Apache POI binaries.
Step 1
Design your report template using Microsoft Word and populate the document with variable placeholders.
Step 2
Save this template as a Word 97-2003 document.
Step 3
Download the latest Apache POI binaries. At the time of writing, the latest version is 3.9 and the utility needed is still under development. The two Java library (jar) files are highlighted.
Step 4
Extract the package and change the current directory to the folder the files were extracted to.
Step 5
For convenience, copy/move the template document to the same directories as the Java libraries.
Step 6
Perform the Word to FO conversion. Enter the command as highlighted.
Step 7
The contents of the FO file should be something similar to this:
Step 8
Place the contents of this file - stuff between the <fo:root> element - within a transformation template.
Note: If Oracle BI Publisher is used to generate the PDFs, then remove the and any child elements within. Consulting the docs for supported elements would be helpful.
Step 9
Replace the placeholders defined in the Word document with elements.
Use XPath to select the values from the XML data file generated by APEX.
Step 10
Images would be removed and replaced by a placeholder comment tag.
Step 11
Include the image file as <fo:external-graphic> elements.
Step 12
Save the file with an XML extension. To see this template in action, click on the "Print" button here.
Known Issue: The graphics element renders correctly when using Oracle APEX Listener 2.0 embedded Apache FOP print rendering engine, but not on apex.oracle.com, which uses Oracle BI Publisher. I am still trying to figure out why and if you do know the reason, I'd be happy if you could share it with me. Thanks! :-)