[ https://issues.apache.org/jira/browse/PDFBOX-807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13056790#comment-13056790 ]
Adam Nichols commented on PDFBOX-807: ------------------------------------- According to my earlier comments, I wasn't able to duplicate this issue. Andrea says it can be duplicated using the code from the issue and confirms that Calling doc.setAllSecurityToBeRemoved(true) before saving fixed the issue. You should be able to save without removing the encryption though, as long as you have the correct password, of course. If anyone is still having issues with this, please comment. If nobody responds, I'll go ahead and close out this issue. > NullPointerException in StandardSecurityHandler.java:261 > -------------------------------------------------------- > > Key: PDFBOX-807 > URL: https://issues.apache.org/jira/browse/PDFBOX-807 > Project: PDFBox > Issue Type: Bug > Components: PDModel > Affects Versions: 1.2.1 > Environment: JDK 1.6.0_21, Windows XP 32 Bit. > Reporter: MH > Assignee: Adam Nichols > Priority: Blocker > > I like to add text to a PDF and used the example code > AddMessageToEachPage.java to do this. I added decryption to support encrypted > docs: > doc = PDDocument.load(sourceFile); > if (doc.isEncrypted()) { > doc.decrypt(ownerPwd); > } > When my document is encrypted, the decryption succeeds without error message, > but for such encrypted docs, when callinf doc.save(), a NullPointerException > occurs: > ----------------------------------------- > java.lang.NullPointerException > at > org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareDocumentForEncryption(StandardSecurityHandler.java:261) > at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1013) > at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:911) > at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:892) > ----------------------------------------------------------------- -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira