Tuesday, May 26, 2015
BI Publisher API Example – Creating PDF Report from XML/RTF?
Oracle has shared us a set of BI Publisher Java Classes for performing various BI Publisher function like converting RTF to XSL-FO, generating PDF output from XSL-FO and XML etc.
In this post, we will generate a PDF output from XML file using the standard Oracle BI Publisher API’s (Java based).
STEP1: Prepare and Convert RTF template to XSL-FO file
Oracle have provided a Java Class to generate PDF output based on XSL-FO file and XML input. Hence, first step is to generate the XSL-FO file based on RTF template. Details are available in another article,
Now, we should be having a XSL-FO file.
STEP2: Prepare the Java wrapper Class for calling Standard class FOProcessor
import java.io.InputStream;import java.io.OutputStream;import oracle.apps.xdo.template.FOProcessor;import oracle.apps.xdo.template.fo.util.FOUtility;import java.io.*;import oracle.apps.xdo.common.pdf.util.PDFDocMerger;import oracle.apps.xdo.batch.DocumentProcessor;public class convertxmltopdf {public static void main(String[] args){try{FOProcessor processor = new FOProcessor();processor.setData(args[0]); //input XMLprocessor.setTemplate(args[1]); //input XSL templateprocessor.setOutput(args[2]); // output PDF File// Set output format (for PDF generation)processor.setOutputFormat(FOProcessor.FORMAT_PDF);// Start processingprocessor.generate();}catch (Exception e){e.printStackTrace();System.exit(1);}System.exit(0);}}
STEP3: Compile the Java wrapper
javac -classpath $CLASSPATH convertxmltopdf.java
Step 4: Copy the Wrapper Class to JAVA_TOP
cp convertxmltopdf.class $JAVA_TOP
STEP5: Verify the Sample RTF template, XSL-FO file and XML File
Input XML:
Actual RTF:
Generated XSL-FO based on Step 1:
Step6: Place the XSL-FO and Input XML file in Desired Directory and Call the Wrapper Java Class
java -classpath $CLASSPATH convertxmltopdf ./INPUTDATAXML.xml ./RTFTEMPLATEEX.xsl ./RTFTEMPLATEEX.pdf
Output PDF:
Do you think this Article is useful?
Subscribe to:
Post Comments (Atom)
Disclaimer
The ideas, thoughts and concepts expressed here are my own. They, in no way reflect those of my employer or any other organization/client that I am associated. The articles presented doesn't imply to any particular organization or client and are meant only for knowledge Sharing purpose. The articles can't be reproduced or copied without the Owner's knowledge or permission.
1 Responses to “BI Publisher API Example – Creating PDF Report from XML/RTF?”
February 28, 2021 at 9:10 PM
Hi Team,
Do we have a way to we can call the XML report which is attached in data definition via API. I understand this example is placing the data definition and RTF template at the particular direcotry and processing the output. But i like to know is there a way where we can use the data definition which is attached in the XML administrator respondibility data defintion screen. Thanks in advance.
Post a Comment