Creating PDF documents from Lotus Notes with PD4ML
(updated May 4, 2010)
Most of the online scenarios of PDF generation on Lotus Domino
platform can be implemented with minimal effort
using PD4ML JSP custom tag library.
This article describes how to automate PDFs generation for documents located
not only in online (Lotus Domino), but as well as in offline (Lotus Notes)
databases.
As a starting point we recommend to look through "Leverage
DXL to Overcome Web Browser Rich Text Limitations" Lance Spellman
Workflow Studios. The document describes the concept of DXL (Domino XML)
language and XSL transformations needed to convert DXL to HTML.
The example Lotus agent, we are going to
introduce, extracts selected document(s) in DXL form from database, performs XSL
transformation of the DXL to HTML, converts the HTML to PDF and stores the
resulting PDFs as attachments to the original document(s). The agent code can be
easily adjusted to your particular needs: sending of emails with PDF
attachments, external archiving of documents in PDF form etc.
We start with a blank database creation in Lotus Domino Designer.
Copy-paste the agent code (R7
agent code) to the agent editor. An
attempt to save would cause an error: there are still missing libraries
there.
In order to add the missing resources press "Edit Project" button and add
pd4ml.jar (or pd4ml_demo.jar) from PD4ML distribution,
ss_css2.jar and dxl4pd4ml.xsl.
There is also optional fonts.jar contains TTF fonts, for
a case it is not possible to refer to a local font directory like "c:\windows\fonts".
save it, switch to Lotus Notes and create a document instance:
Now we can activate the agent with Actions->Create PDF menu item. Close the
document and open it again (No idea how to refresh the document view from Java
code).
The new attachment icon should allow us to open the just generated PDF version
of the document.
Remarks:
1. The XSL we use in the example does the basic transformation to HTML,
handles images, attachments and page breaks, but it is still far away from
the full DXL features support. We constantly work on improving it. Please request PD4ML support
for the most recent and feature-rich version of DXL converting XSL stylesheet.
2. The example is tested with Lotus Notes/Domino 6.5.4. Older versions do not
allow to load resources via Java ClassLoader, so it is needed to store the XSL
to the database as a "normal" document and to read it from there by usual for
Lotus Notes way.
3. A smooth support of DXL features required some changes in PD4ML
functionality. For the described scenario it is recommended to use PD4ML
v3.2.1b3 and above.
4. The agent debug output can be seen under File->Tools->Show Java Debug
Console
5. The following needs to be done to set the Java properties for Domino on
the iSeries:
Create an entry in the notes.ini pointing to custom Java user
settings file (JavaUserOptionsFile=/notes/wdomino1/javaOptions.txt)
Create the file using the ASCII character set and add the following
entry or any other properties that need to be set... java.awt.headless=true
6. Starting with Lotus Notes R7 the way of XSL transformation has been
changed for Lotus platform. Here is an updated NSF demo database,
compatible with the changes.
Note: sometimes Lotus Notes fails to start the PDF generation
agent of the demo database and hangs. Actually Lotus does not trust the fake
agent signature and for some reason it fails to show its security alert
dialog. Try to restart Lotus and to reopen the database.
7. For some document types, producing broken PDF layout, (especially if generated PDFs contain snippets of LotusScript code) it helps after String xml = dxl.exportDxl(tmp); >Java agent code line is substituted with String xml = dxl.exportDxl(doc);.