Try something like this:

PDDocument doc = null;
try {
    doc = PDDocument.load(yourFile);
    if(doc.isEncrypted()) {
        StandardDecryptionMaterial sdm = new 
StandardDecryptionMaterial("");
        doc.openProtection(sdm);
    }
} finally {
    try { if(doc != null) doc.close(); } catch(Exception ex) { } }
}

Also, if you want to remove the security when you save, just call
doc.setAllSecurityToBeRemoved(true);
doc.save(fos); // fos being your FileOutputStream
fos.close();

---- 
Thanks,
Adam





From:
Gary LosHuertos <[email protected]>
To:
[email protected]
Date:
08/27/2010 10:58
Subject:
Can't decrypt with default password, but can open without password



Hello all,

I have a collection of PDFs I'm extracting text from programmatically, and
some of them are encrypted.  All of them can be opened in OS X's Preview
without supplying a password, but when decrypting with PDFBox, a small
portion of result in an exception on decryption:

Exception in thread "main"
org.apache.pdfbox.exceptions.CryptographyException: Error: The supplied
password does not match either the owner or user password in the document.
at
org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.decryptDocument(StandardSecurityHandler.java:231)
at 
org.apache.pdfbox.pdmodel.PDDocument.openProtection(PDDocument.java:1111)
...

This happens both with

doc.openProtection(new StandardDecryptionMaterial(""));

and

doc.decrypt("");

(not that I'm sure there's a difference).  Is there some magic that 
Preview
is doing to decrypt the document, or am I just hosed?  Any help would be
greatly appreciated.  Thanks!

Gary LosHuertos
Arc90



?  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