Description
I got this error while trying to save a PDF where I added encryption:
ava.lang.ClassCastException: org.apache.pdfbox.cos.COSObject cannot be cast to org.apache.pdfbox.cos.COSArray
at org.apache.pdfbox.cos.COSDocument.getDocumentID(COSDocument.java:379)
at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareDocumentForEncryption(StandardSecurityHandler.java:300)
at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1306)
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1121)
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1102)
Inspecting the pdf in a REPL, I found out that the ID is not a direct array, but a reference to one. I changed the line 401 of COSDocument.java to use getDictionaryObject instead of getItem and it seemed to fix the problem.