Integrated Document Solutions
for Business Applications

Sort Posts

Get Fresh Updates

Home / Blog / Current Page

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

Posted on by Brent Lowe

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.


Share This



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

  1. Balwant says:

    is there a way to get Text format output from RTF template and XML?
    (Apart from etext template means RTF Template is developed by form field method)

  2. Indranil says:

    Hi Brent. I am very new to BI Publisher. I have a requirement to create and email PDF invoices to customers. The invoices will be stored as XML in the database and based on the type of invoice, I have to fetch the invoice from DB, select the respective template and create the PDF. Can you tell me how to start with the development ? What should I begin with and how to proceed ? You help is greatly appreciated.

    • Brent Lowe says:

      Hi Indranil,

      I think it really just all depends. Essentially you first have to get your XML data and your template. From there you can use these APIs to create a final PDF. I would start by figuring out how you are going to get those 2 base requirements (XML and template) and then write a program around those known quantities.

  3. Adalberto says:

    is possible after developing a report in BI PUBLISHER, export it into the peoplesoft?

    Tanks

    • Brent Lowe says:

      Hi Adalberto,

      Unfortunately, I have not kept up with BIP in PeopleSoft. Your best bet will likely be the PeopleSoft documentation.

      Sorry, I couldn’t give you a more definite answer.

  4. Krishna says:

    Hi Brent,

    I have been using BI Publisher 10g series for generating reports. I used DataProcessor API to generate the Data xml.
    Now when I try to do the same in the BI Publisher 11g series, it says the DataProcessor API is no longer available.
    Is there a change in the way I need to approach in creating reports in 11g?
    Why is the DataProcessor API not part of 11g?
    What should I do to make my 10g code work with 11g?

    • Brent Lowe says:

      Hi Krishna,

      I have some good and bad news for you. First the bad.

      According to My Oracle Support Note 1385953.1 this API has been discontinued with no reason given. In case you do not have access to My Oracle Support, I’ve copied the contents of the note below:

      BI Publisher 11g No Longer Delivers the DataProcessor API (Doc ID 1385953.1)
      ——————————————————————————–
      Modified:Nov 26, 2013 Type:HOWTO

      Applies to:
      BI Publisher (formerly XML Publisher) – Version 11.1.1.5.0 to 11.1.1.5.0 [Release 11.1]
      Information in this document applies to any platform.

      Goal

      In BI Publisher 10g the BI Publisher API (oracle.apps.xdo.dataengine.DataProcessor) was used to directly generate reports. But it appears to no longer be available in BI publisher 11g.

      Solution

      The un-published Bug 8483393 confirms that Development purposely discontinued the Data Processor API from the 11g xdocore.jar.

      Now for the good. Well…. potentially good… can’t promise anything. Doing some snooping around, it appears that the class has been moved to the xdo-server.jar file in the package: oracle.xdo.dataengine.DataProcessor

      So… I’m not 100% that it’s the SAME DataProcessor as you are used to in 10g, but hopefully this is a start for you.

      Let me know what you find and I’ll make an official post out of it, cool?

      • Krishna says:

        Thanks Brent.
        This jar has a dependency on some other jar which is throwing errors :(.
        It seems, the DataProcessor will not be supported in the 11.x series (As per a few updates in the Bug details).
        Have to wait to if this will part of any future releases.

        Regards,
        Krishna

  5. Shubhangi says:

    Hey i am getting below error whiling creating PDF from XML and RTF Templates

    Error:

    org.xml.sax.SAXParseException; lineNumber: 44; columnNumber: 1; : XML-20100: (Fatal Error) Expected ‘EOF’.

    Code:

    String pdfName = “/AgroSoftTech/Reports/Bills/Bill_No_”+bill_no + “.pdf”;
    byte[] dataBytes = null;

    byte[] inDataBytes =null;

    try
    {

    RTFProcessor processor = new RTFProcessor(“/AgroSoftTech/Templates/BillReport.rtf”);
    ByteArrayOutputStream xslOutStream = new ByteArrayOutputStream();
    processor.setOutput(xslOutStream);
    System.out.println(“BEFORE process()”);
    processor.process();

    System.out.println(“RTFProcessor”);

    //Use XSL Template and Data from the VO to generate report and return the OutputStream of report
    ByteArrayInputStream xslInStream = new ByteArrayInputStream(xslOutStream.toByteArray());

    FOProcessor FoProcessor = new FOProcessor();
    FoProcessor.setData(“/AgroSoftTech/Reports/Bills/Bill_No_2.xml”);
    FoProcessor.setTemplate(xslInStream);
    FoProcessor.setOutput(pdfName);
    FoProcessor.setOutputFormat(FOProcessor.FORMAT_PDF);

    FoProcessor.generate();

    System.out.println(“Success for Run Report”);

    }
    catch (XDOException e)
    {
    System.out.println(“XDOException!!!!!!!!!!!!!!!!!”+e.getMessage());
    e.printStackTrace();
    }
    catch(FileNotFoundException ex)
    {
    System.out.println(“FileNotFoundException!!!!!!!!!!!!!!!!!”+ex.getMessage());
    }
    catch(IOException exp)
    {
    System.out.println(“IOException!!!!!!!!!!!!!!!!!”+exp.getMessage());
    }

Leave a Reply to Thuthuy Cancel reply

Your email address will not be published. Required fields are marked *