Reputation: 4216
In my program I am downloading misc. PDF documents and at the very end I want to merge those into one combined document using Apache pdfbox (v1.8.8). For some strange reason the PDFMergerUtility fails claiming that the files are encryped - which they are obviously not! I can open them in Adobe Reader and other PDF viewers without any issue and without having to provide any password.
The Java exception and stack trace reads:
Feb 28, 2015 6:25:54 PM org.apache.pdfbox.pdfparser.PDFParser parse
INFO: Document is encrypted
Failed to merge all files into downloaded\page merged.pdf: Error: source PDF is encrypted, can't append encrypted PDF documents.
java.io.IOException: Error: source PDF is encrypted, can't append encrypted PDF documents.
at org.apache.pdfbox.util.PDFMergerUtility.appendDocument(PDFMergerUtility.java:284)
at org.apache.pdfbox.util.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:241)
at org.apache.pdfbox.util.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:194)
at mmo.pull_ct.PullCT.mergePDFs(PullCT.java:481)
Anybody having the same issue and/or maybe knows a fix or work-around? This is using Java (1.)8 under Windows 8.1 (x64).
Upvotes: 2
Views: 3457
Reputation: 8271
As the pdf have empty password. This worked for me in a test project. Adding this answer as it took some time for me to figure it out, may help someone looking for the same issue.
PDDocument dl = PDDocument.load(is);
if (dl.isEncrypted()) {
// then try to load using
dl.decrypt("");
dl.setAllSecurityToBeRemoved(true);
// save a copy of the file
dl.save(tempPath);
}
Upvotes: 0
Reputation: 4216
Answered by the comments from Tilman Hausherr and mkl above. The Files were encrypted but using an empty password. Trying that got me going. Thanks again!
Upvotes: 1