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

ClassCastException on COSDocument#getDocumentID

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.6.0
    • Fix Version/s: 1.7.0
    • Component/s: PDModel
    • Labels:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: