Hi ,

Thanks for your help Adam.

Today I have tried to change the permissions of my PDF, and your code worked fine ... I access the PDF using 'Owner Password'. My problem is I want to write to the encrypted PDF ... This works fine, until the line of saving the PDF, I get this Exception :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareDocumentForEncryption(StandardSecurityHandler.java:261)
        at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1002)


This exception just appears even if I don't write anything in the PDF ... Just when I try to save it, ex :
pdfFile = PDDocument.load( file );  // Open this pdf to edit.// Decrypt the pdf 
if it's encrypted :
if( pdfFile.isEncrypted() ) {                StandardDecryptionMaterial dm = new 
StandardDecryptionMaterial( "1234" );
        pdfFile.openProtection( dm );
}

pdfFile.save( file );  // Exception here.
pdfFile.close();


Best regards ,
Hesham

--------------------------------------------------
From: <a...@swmc.com>
Sent: Friday, October 30, 2009 5:53 PM
To: <pdfbox-users@incubator.apache.org>
Cc: <pdfbox-users@incubator.apache.org>
Subject: Re: PDF Permissions

Here are the basics:
       PDDocument doc = null;
       try {
           doc = PDDocument.load(someFile);
           StandardDecryptionMaterial sdm = new
StandardDecryptionMaterial("yourPasswordGoesHere");
           doc.openProtection(sdm);
           // use the document like normal
       } catch(...) {
           // decryption error
       } finally {
           if(doc != null)
               doc.close();
       }




"Hesham G." <heshamgne...@gmail.com>
10/30/2009 04:37
Please respond to
pdfbox-users@incubator.apache.org


To
<pdfbox-users@incubator.apache.org>
cc

Subject
Re: PDF Permissions






I am having problems with encrypted PDFs too. I don't know but I think
there
are things wrong with the Encryption / Decryption classes.

Best regards ,
Hesham




?  Click here to submit conditions

This email and any content within or attached hereto from Sun West Mortgage Company, Inc. is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named on this email. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this email information is strictly prohibited, and that the documents should be returned to this office immediately by email. Receipt by anyone other than the intended recipient is not a waiver of any privilege. Please do not include your social security number, account number, or any other personal or financial information in the content of the email. Should you have any questions, please call (800) 453 7884. =

Reply via email to