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

ClassCastException (PDColor.java:66)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.24, 2.0.26
    • 2.0.27, 3.0.0 PDFBox
    • PDModel
    • None

    Description

      We are currently running PDFBox 2.0.24 & 2.0.26, but I see the code is identical in the trunk.

      Certain PDFs are throwing the exception shown below in our production system.  In these cases,  rather than the array containing a list of COSNumbers, it actually contains a single item - another COSArray.

      That COSArray then has an array of COSNumbers.  If I insert the following lines of code at line 62 to use the inner COSArray, the PDF renders properly.

                  if ((array.size() == 1) && (array.get(0) instanceof COSArray))
                      array = (COSArray) array.get(0);

       

      Unfortunately, we do not generate the PDFs ourselves and our documents contain sensitive information so I am unable to provide an example.

       

      Exception:

      java.lang.ClassCastException: class org.apache.pdfbox.cos.COSArray cannot be cast to class org.apache.pdfbox.cos.COSNumber (org.apache.pdfbox.cos.COSArray and org.apache.pdfbox.cos.COSNumber are in unnamed module of loader 'app')
      at org.apache.pdfbox.pdmodel.graphics.color.PDColor.(PDColor.java:66)
      at org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDFreeTextAppearanceHandler.extractNonStrokingColor(PDFreeTextAppearanceHandler.java:424)
      at org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDFreeTextAppearanceHandler.generateNormalAppearance(PDFreeTextAppearanceHandler.java:111)
      at org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDFreeTextAppearanceHandler.generateAppearanceStreams(PDFreeTextAppearanceHandler.java:75)
      at org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup.constructAppearances(PDAnnotationMarkup.java:897)
      at org.apache.pdfbox.rendering.PageDrawer.showAnnotation(PageDrawer.java:1521)
      at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:281)
      at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:347)
      at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:268)

      Attachments

        Activity

          People

            tilman Tilman Hausherr
            John Petersam John Petersam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: