Apache pdfbox claims that PDF documents are encrypted (but they are not!) - fix?

余生长醉 提交于 2019-12-12 22:12:41

问题


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).


回答1:


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!




回答2:


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);
 }


来源:https://stackoverflow.com/questions/28799979/apache-pdfbox-claims-that-pdf-documents-are-encrypted-but-they-are-not-fix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!