Merging pdf documents using the BI-Publisher API

Marcos Claver 1
0 0
Read Time:2 Minute, 3 Second

BI Publisher (named XML-Publisher until a few weeks ago, but what is in the name) offers besides the possibility to create documents also the possibility to interact with the application through its application programming interface. These apis offer the programmer several functions of which the PDF document merger is one.
This morning I looked into the functionality this api could offer me in one of my projects for which I need to create a singel pdf document out of multiple documents. How does it work and what do you need to do

  • Since we want to use the BI-Publisher api we will need to get this one first. Download XML-Publisher and unzip it.
  • Start JDeveloper and create a new application and a new project
  • Add a java class to the project. This class will implement the code to merge pdf documents to one single document
  • Add the XML-Publisher API’s jar files to the project. Note that the jar files are located in the  <XMLP562_win>manual\lib directory where <XMLP562_win> is the directory where you unzipped the XML-Publiser zipfile.

Ok so now for the code:
Create input streams and a output stream

      FileInputStream[] input = new FileInputStream[2];
      input[0] = new FileInputStream("PDFDoc1.pdf");
      input[1] = new FileInputStream("PDFDoc2.pdf");
      FileOutputStream output = new FileOutputStream("MergedPDF.pdf");

Create a new PDFDOcMerger object with as input the input and output streams

      PDFDocMerger pdfMerger = new PDFDocMerger(input, output);

optionally set the page number and a watermark

      pdfMerger.setPageNumberCoordinates(300, 20);
      pdfMerger.setPageNumberFontInfo("Arial", 10);
      pdfMerger.setPageNumberValue(1, 1);
      pdfMerger.setTextDefaultWatermark("DRAFT");

Merge the pdf documents with the PDFMerger class

      pdfMerger.process();

Execute the Java class and you will have your documents merged.
The full class below

package nl.amis.xmlpublisher;

   import oracle.apps.xdo.XDOException;
   import oracle.apps.xdo.common.pdf.util.PDFDocMerger;
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
   import java.io.FileOutputStream;

public class XMLPublisher {
public XMLPublisher() {
}

public void pdfDocumentMerger() {
try {
FileInputStream[] input = new FileInputStream[2];
input[0] = new FileInputStream(“PDFDoc1.pdf”);
input[1] = new FileInputStream(“PDFDoc2.pdf”);

FileOutputStream output = new FileOutputStream(“MergedPDF.pdf”);
PDFDocMerger pdfMerger = new PDFDocMerger(input, output);

pdfMerger.setPageNumberCoordinates(300, 20);
pdfMerger.setPageNumberFontInfo(“Arial”, 10);
pdfMerger.setPageNumberValue(1, 1);
pdfMerger.setTextDefaultWatermark(“DRAFT”);
pdfMerger.process();
pdfMerger = null;
} catch (XDOException e) {
System.out.println(“XDOException” + e.getMessage());
} catch (FileNotFoundException e) {
System.out.println(“FileNotFoundException ” + e.getMessage());
}
}

public static void main(String[] argv) {
MLPublisher xmlPublisher = new XMLPublisher();
xmlPublisher.pdfDocumentMerger();
}
}

 

 

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

One thought on “Merging pdf documents using the BI-Publisher API

  1. Hi Marcos,
    I am in need of merging two pdf documents each having single pages. The first page is just text and second is protected with password. when i try to merge these two documents, i receive no error but the merged document has second page always blank. The password protected pdf is also merged with no issues. If its contents are displayed at first, the second page of the plan pDf is still blank… can you please help me if there is any issue with pdf or need some config to merge without any issues.
     
    I appreciate your help.
     
    Thanks.

Comments are closed.

Next Post

EBS Release 12 "SWAN" User Interface

Last week AMIS organized an " E-Business Suite Release 12 (EBS R12) New Features" session.  It became obviously that EBS R12 has many new features and the improved user interface is only one of them. Nevertheless, the new "Swan" user interface is for most end users an important one and end users are curious to experience […]
%d bloggers like this: