X

An Oracle blog about BI Publisher

Merge and Secure PDFs

Another question on the forum that deserves a bit more than a 5 line answer. Neeraj has been trying to merge PDF documents using the Publisher APIs. From the question I think he has merged the docs but he wants to add a security password on top of the merged docs too.



I am trying to merge multiple pdf document and want to secure the output using pdf security attributes.
Is there a way to achieve this while pdf merge ?

(I am able to do so while generating the pdf using FO Processor but not while merging existing pdf files.)

There are several ways to merge PDFs using APIs, the simplest is the PDFDocMerger API. Its a pretty simple API, just get the documents to be merged into an array, specify the output file and then call the process method.

package pdftester;



 

import java.io.File;
import java.util.Properties;
import oracle.apps.xdo.XDOException;
import oracle.apps.xdo.common.pdf.util.PDFDocMerger;



public class PDFMerger {
    public PDFMerger() {
   
    // Output destination of the merged PDF document.
    File outFile = new File("c:\\temp\\mergePDF.pdf");    
// PDF documents to be merged.
    File[] inpFiles = new File[2];
    inpFiles[0] = new File("c:\\temp\\1.pdf");
    inpFiles[1] = new File("c:\\temp\\2.pdf");
    // Create PDFDocMerger instance.
    PDFDocMerger pdfMerger = new PDFDocMerger(inpFiles, outFile);
    // Set the security property
    Properties prop = new Properties();
    prop.put("pdf-security","true");
    prop.put("pdf-open-password","welcome");
    pdfMerger.setConfig(prop);
      
    // Run the merging process.
    try {
         pdfMerger.process();
   
        } catch (XDOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        PDFMerger pDFMerger = new PDFMerger();
    }
}



Neeraj wanted to add a password to the resulting document. We can us the setConfig method to set the appropriate properties to set the password.

    // Set the security property
    Properties prop = new Properties();
    prop.put("pdf-security","true");
    prop.put("pdf-open-password","welcome");
    pdfMerger.setConfig(prop);


Of course you can fetch that password from some repository rather than hard coding it.
If you want to have a go, you can get the PDFs and the java from here.

Join the discussion

Comments ( 5 )
  • Andy Thursday, August 2, 2007
    Hi,
    I'm having this problem for quite sometime now and can't get it to work. I知 trying to merge 2 pdf's using App Engine / peoplecode. I've used RTF as templates for these. Can you please give me a sample code on how to do this in pplcode? My code is not working. This is what I have coded in AE/pplcode action:
    import PSXP_ENGINE:*;
    &oPDFMerger = create PSXP_ENGINE:PDFMerger();
    &sErr = 灯;
    &sFilesArray = CreateArray(&sTemplateId);
    &sFilesArray.Push(&sTemplateId2);
    &bResult = &oPDFMerger.mergePDFs(&sFilesArray, &sOutputFile, &sErr);
    It is not merging the docs :(
    Thanks!
  • Tim Dexter Thursday, August 2, 2007

    Hi Andy


    I have forwarded your question to the PS dev folks. Will get back to you.


    Tim  

  • Jayalakshmi Monday, June 29, 2009
    Any updates on How to use the PDFMerger. In my case it picks only the first file and remaining files are not merged to the output. Thanks!
  • Rupesh Wednesday, September 9, 2009
    Hi Tim,
    I can merge two or more pdf files using mergePDFs successfully in PeopleSoft. But when I tried to merge a password secured pdf file with a normal pdf file, the outcome is a blank pdf file.
    Do we've any work around for this ? I do not need peoplesoft specific answer, just show me some pointer and I'll try to workout the solution in PSFT.
    Many Thanks,
    Rupesh
  • Subhash Friday, September 24, 2010
    we are tools 8.49.13 - pdf merger worked for me. although i haven't tried security piece.
    thanks for the blog
    Subhash
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.