Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-1269

ClassCastException on COSDocument#getDocumentID

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.6.0
    • 1.7.0
    • PDModel
    • None

    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.

      Attachments

        Activity

          People

            lehmi Andreas Lehmkühler
            jpbougie Jean-Philippe Bougie
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: