In Part 1 I discussed the process of getting data from Domino to PDF using only open standards. In this part I want to start backwards: If I have valid XSL:FO, how do I get the PDF output? In a later installment I will discuss what XSL:FO is capable of and how to create it using XSLT. Finally I will discuss how to extract XML from your data source (Domino or others).
I choose the backwards approach since it is easier to understand walking from the desired output towards a stylesheet than creating a stylesheet if the result isn't clear. Bear with me for this approach.
I will use Apache FOP as my rendering engine. The Quickstart compresses the needed steps neatly into 1-2-3 (pun intended):
This is the easy part. Pick one of the mirror servers and get fop-1.0-bin.zip (24M) - check if you read this later if there is a newer version. Extract it to a directory of your choice, we will import/copy what we need from there
You have choices:
- copy the Fop files into jvm/lib/ext (bad idea)
- import it into an NSF (twice: once for agents, once for XPages)
- create a plug-in (good for sidebar and XPages, not good for agents)
The FOP website provides a good overview on general Java use as well as servlet specifics. Using that information as template it is not too hard to implement a managed bean that takes a XMLDocument and an optional Stylesheet and returns the rendered PDF as result
var response = exCon.getResponse();
var out = response.getOutputStream();
// In this example the text in sessionScope.longText will be rendered
var written = sessionScope.longText != "" ? "<text>"+sessionScope.longText+"</text>" : null;
// Writes the default rendering out
// Stop the page from further processing;
As usual YMMV.