Using BI Publisher APIs to create PDF from XML and RTF Templates

I was working on a customer issue last week where we were getting some odd results when using the BI Publisher API’s to burst data to create PDFs. Specifically, data was not showing up in the output PDF. Turns out the issue was with the bursting control file which was easily resolved.

However, during the process of troubleshooting I wanted to see what would happen if I took bursting completely out of the equation and just used the BIP APIs to create a PDF from input XML and a RTF template (without any bursting). So I fired up the BIP documentation and found the APIs for the RTF Processor and FO Processor Engines and put together a quick and dirty Java function to test out my theory. It’s listed below:

Input Parameter 1 = RTF Template
Input Parameter 2 = XML Data
Input Parameter 3 = Name of PDF output file

File tmpFile = File.createTempFile("biptest",".tmp");

RTFProcessor rtf = new RTFProcessor(args[0]); // RTF template Input
rtf.setOutput(tmpFile.getAbsolutePath());
rtf.process();

FOProcessor fo = new FOProcessor();
fo.setData(args[1]); // XML Input
fo.setTemplate(tmpFile.getAbsolutePath());

fo.setOutput(args[2]); // PDF output
fo.setOutputFormat(FOProcessor.FORMAT_PDF);

try {
fo.generate();
} catch (Exception ex) {
ex.printStackTrace();
}

tmpFile.delete();

As you can see there is no direct way to go from RTF template to PDF output. Instead you have to first convert the RTF template to XSL-FO, then combine the XSL-FO with the XML to create the PDF output.

I thought it was timely and may be helpful to others since I stumbled across a question on the Oracle BIP forums yesterday regarding a need for this same information.

Interested in Learning More? Let’s Connect!

Related Articles

7
Share This