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

NPE warn during text extraction caused by character encoding not set

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5.0
    • Fix Version/s: 1.6.0
    • Component/s: Text extraction
    • Labels:
      None

      Description

      During text extraction, the following NPE stack is printed with a warn level.

      17:34:58,762 WARN [PDFStreamEngine] java.lang.NullPointerException
      java.lang.NullPointerException
      at org.apache.pdfbox.pdmodel.font.PDSimpleFont.getFontHeight(PDSimpleFont.java:136)
      at org.apache.pdfbox.util.PDFStreamEngine.processEncodedText(PDFStreamEngine.java:408)
      at org.apache.pdfbox.util.operator.ShowTextGlyph.process(ShowTextGlyph.java:62)
      at org.apache.pdfbox.util.PDFStreamEngine.processOperator(PDFStreamEngine.java:551)
      at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:274)
      at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:251)
      at org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:225)
      at org.apache.pdfbox.util.PDFTextStripper.processPage(PDFTextStripper.java:442)
      at org.apache.pdfbox.util.PDFTextStripper.processPages(PDFTextStripper.java:366)
      at org.apache.pdfbox.util.PDFTextStripper.writeText(PDFTextStripper.java:322)
      at org.apache.pdfbox.util.PDFTextStripper.getText(PDFTextStripper.java:242)
      at org.nuxeo.ecm.core.convert.plugins.tests.TestPDFEncodingWarn.extract(TestPDFEncodingWarn.java:36)

      Digging in the problem, I've found that the encoding field of the true type font was not set during the dictionary load.

      Thread [main] (Suspended (breakpoint at line 113 in PDTrueTypeFont))
      PDTrueTypeFont.<init>(COSDictionary) line: 113
      PDFontFactory.createFont(COSDictionary) line: 116
      PDFontFactory.createFont(COSDictionary, Map) line: 75
      PDResources.getFonts(Map) line: 115
      PDFTextStripper(PDFStreamEngine).processSubStream(PDPage, PDResources, COSStream) line: 243
      PDFTextStripper(PDFStreamEngine).processStream(PDPage, PDResources, COSStream) line: 225
      PDFTextStripper.processPage(PDPage, COSStream) line: 442
      PDFTextStripper.processPages(List<COSObjectable>) line: 366
      PDFTextStripper.writeText(PDDocument, Writer) line: 322
      PDFTextStripper.getText(PDDocument) line: 242

      I've attached the PDF file and test class I've used for reproducing.

        Attachments

        1. nutcracker.pdf
          55 kB
          Stephane Lacoin
        2. TestPDFEncodingWarn.java
          1 kB
          Stephane Lacoin

          Activity

            People

            • Assignee:
              lehmi Andreas Lehmkühler
              Reporter:
              slacoin Stephane Lacoin
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: