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.

Comments:

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!

Posted by Andy on August 02, 2007 at 02:08 AM MDT #

Hi Andy

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

Tim  

Posted by Tim Dexter on August 02, 2007 at 04:46 AM MDT #

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!

Posted by Jayalakshmi on June 28, 2009 at 09:51 PM MDT #

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

Posted by Rupesh on September 09, 2009 at 07:55 AM MDT #

we are tools 8.49.13 - pdf merger worked for me. although i haven't tried security piece. thanks for the blog Subhash

Posted by Subhash on September 24, 2010 at 07:29 AM MDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Follow bipublisher on Twitter Find Us on Facebook BI Publisher Youtube ChannelDiscussion Forum

Join our BI Publisher community to get the most and keep updated with the latest news, How-to, Solutions! Share your feedback and let us hear your voice @bipublisher on Twitter, on our official Facebook page, and Youtube!

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today