ShowTable of Contents
IBM® Web Experience Factory (hereafter called WEF) is a powerful and flexible development tool that allows developers to rapidly create, build, customize, and deploy portlets to IBM WebSphere® Portal. Creating a PDF file on the fly often becomes a challenging task, especially when a wide variety of PDFs must be generated with conditional text, images, and repetitive blocks.
The builder described in this article generates PDFs on the fly, using XSL files (*.fo) and the Apache Formatting Objects Processor (FOP) library
. Basically FOP is great for template-based PDF generation, but in our builder, XSL-FO syntaxes are extended with custom XML elements that allow us to add dynamic behavior during the generation of the PDF.
This article illustrates a scenario in which values are picked up from variables defined in the FOP model, or conditional text is displayed by use of a variable or iterated over the XML to display the repeated blocks.
We also put the image generated from flash or charts into a PDF, using WEF's back-channel access URL and servlet streaming. There is no limit to the features you can get while generating a PDF; you just need to extend the logic accordingly to accommodate the features you require.
This builder adds the generated document to the ServletResponseOutputStream, ready to view or download from the Web page, and also supports links, buttons, or image buttons to trigger the generation of the PDF.
This article is divided into following sections:
(1) Installing custom builders in WEF Designer
(2) Using the builder with a given XSL-FO
(3) Adding dynamic capabilities to the XSL-FO file
(4) Builder implementation details
(5) Source, examples and learning
It is assumed that readers have experience with deploying portlets in WebSphere Portal and are aware of basic concepts involved in portlet development using WEF.
Installing custom builders
Download the PDFBuilder.zip file attached to this article and use a compression utility to extract all the files onto your hard disk, for example, into the directory C:\temp. This creates a folder called PDFBuilder in the C:\temp folder. The file structure is shown in figure 1.
Figure 1. PDFBuilder.zip file structure
The PDF_Builder directory contains two folders. The first folder is install_files, in which there are seven archive files:
- PDFBuilder.jar: Contains the custom builder classes
- custom_pdf_builder.zip: Contains the custom builder definitions
The second folder, sample_model, contains the file PDFBuilderSample.model. There are two options for installing the custom builders, either (1) into a project in the workspace or (2) into WEF Designer so that the custom builders are available to all models.
With the first option, only one project is affected; new projects, other projects in the workspace, and projects in other workspaces are not affected. If, however, you install into WEF Designer, then all projects created by WEF Designer thereafter have the files copied into their workspaces.
Installing into a project in the workspace
Import the attached PDF_Builder_Archive.zip archive or place
• All .jar files in the following location: \\WebContent\WEB-INF\lib
• Custom_pdf_builder.zip in \\WebContent\WEB-INF\builders
• Sample_model directory in \\WebContent\WEB-INF\ models\
• Images directory in \\WebContent
• pdf_templates directory in \\WebContent\
After you restart WEF Designer, a custom builder is available in the builder call list.
Installing into WEF Designer
Installing the custom builders into WEF Designer makes the custom builders available to all models created thereafter with that version of WEF Designer.
Close WEF (if it is open) and place:
• All .jar files in \FeatureSets\ Web-App_8.0.0 \Templates\Project\wpf.war\WEB-INF\lib
• Custom_ custom_pdf_builder.zip in \FeatureSets\ Web-App_8.0.0 \Templates\Project\wpf.war\WEB-INF\builders
• Images directory in \FeatureSets\ Web-App_8.0.0 \Templates\Project\wpf.war
• pdf_templates directory in \FeatureSets\ Web-App_8.0.0 \Templates\Project\wpf.war
Restart WEF Designer and verify that the custom builder is present.
Verifying custom builders
After successfully adding the .jar files and builders.zip, you should see "PDF Builder" in the category "Custom Builders", as shown in figure 2.
Figure 2. Builder Picker window