JAVA Concurrent Program in Ebusiness to Merge Two PDF Files.
This program will merge two pdf files available in UNIX directory into a new single pdf file.
This can be used to merge multiple outputs of BI reports into one output file. This is just example of simple Binding capability available for BI Publisher.
Prerequisite:
Copy pdfs files you want to merge to the Unix Server Directory.
For testing purpose I had copied to the files to same location where my Java Class file is located.
I.e. /u01/orr12/orrvis/apps/apps_st/comn/java/classes/oracle/apps/fnd/cp/request/
Or $JAVA_TOP/oracle/apps/fnd/cp/request
Program will have following Input Parameters:
Input File 1
Default Value: /u01/orr12/orrvis/apps/apps_st/comn/java/classes/oracle/apps/fnd/cp/request/PDF_FILE_1.pdf
Input File 2
Default Value: /u01/orr12/orrvis/apps/apps_st/comn/java/classes/oracle/apps/fnd/cp/request/PDF_FILE_2.pdf
Output File
Default Value: /u01/orr12/orrvis/apps/apps_st/comn/java/classes/oracle/apps/fnd/cp/request/PDF_OUTFILE.pdf
Note: The full path needs to be mentioned in the parameter along with filename.
Concurrent Executable & Concurrent Program Definition:
Execution File Name: Class Name: Java Class File Name
Ensure Token is set appropriately as this will be used in the Java Code to fetch the Parameter Name and its Value.
Recommended to keep the “Parameter” & Token same and use it the Java Code.
Java Code:
import java.io.*;
import oracle.apps.fnd.util.*;
import oracle.apps.xdo.common.pdf.util.PDFDocMerger;
public class XXMergeTest1 implements JavaConcurrentProgram
{
public void runProgram(CpContext pCpContext)
{
ReqCompletion lRC = pCpContext.getReqCompletion();
try
{
OutFile lOF = pCpContext.getOutFile();
LogFile lLF = pCpContext.getLogFile();
ParameterList lPara = pCpContext.getParameterList();
int inputNumbers;
inputNumbers = 2;
FileInputStream[] inputStreams = new FileInputStream[inputNumbers];
FileOutputStream outputStream = new FileOutputStream("TEST");
while(lPara.hasMoreElements())
{
NameValueType aNVT=lPara.nextParameter();
lLF.writeln("Parameter Name: " + aNVT.getName(), LogFile.STATEMENT);
lLF.writeln("Parameter Value: " + aNVT.getValue(), LogFile.STATEMENT);
if (aNVT.getName().equals("OUTPUT_FILE1"))
outputStream = new FileOutputStream(aNVT.getValue());
if (aNVT.getName().equals("INPUT_FILE1"))
inputStreams[0] = new FileInputStream(aNVT.getValue());
if (aNVT.getName().equals("INPUT_FILE2"))
inputStreams[1] = new FileInputStream(aNVT.getValue());
}
PDFDocMerger docMerger = new PDFDocMerger(inputStreams, outputStream);
docMerger.mergePDFDocs();
docMerger = null;
lRC.setCompletion(ReqCompletion.NORMAL, "Request Completed Normal");
}
catch(Exception e)
{
lRC.setCompletion(ReqCompletion.ERROR, e.toString());
}
}}
Assuming the files have been transferred to the location as mentioned in the parameter default values, the Program can be tested to check if the two pdf files are merged together into new pdf file.
Attach the Concurrent Program to any Responsibility using the Request Group.
Submit the Concurrent Request with default parameters. You can change the file name of the Output File.
Upon successful completion of the program. Check in the UNIX Server for the new file.
Vive !!!
No comments:
Post a Comment