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

Call to DictionaryEncoding.getEncoding () throws NullPointerException for some PDF's

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0.20
    • Fix Version/s: 2.0.21, 3.0.0 PDFBox
    • Component/s: PDModel
    • Labels:
      None

      Description

      Wenn iterating all fonts in a PDF a call to PDSimpleFont.getEncoding().getEncodingName () throws a NullPointerException inside the library code for the attached sample-PDF.

      The situation can be reproduced, when running the following loop for the attached PDF (test.pdf):

       

       

              PDDocument document = PDDocument.load (file);
              int pages = document.getNumberOfPages ();
              for (int i = 0; i < pages; ++i)
              {
                  PDPage page = document.getPage (i);
                  PDResources resources = page.getResources ();
                  if (resources == null)
                      continue;
                  Iterator<COSName> iter = resources.getFontNames ().iterator ();
                  while (iter.hasNext ())
                  {
                      COSName cos = iter.next ();
                      try
                      {
                          PDFont font = resources.getFont (cos);
                          System.out.println (font.getName ());
                          if (font instanceof PDSimpleFont)
                          {
                              PDSimpleFont simpleFont = (PDSimpleFont) font;
                              Encoding encoding = simpleFont.getEncoding ();
                              if (encoding != null)
                              {
                                  try
                                  {
                                      System.out.println ("* encoding="+encoding.getEncodingName ());
                                  }
                                  catch (Exception e)
                                  {
                                      e.printStackTrace ();
                                  }
                              }
                          }
                      }
                      catch (IOException e)
                      {
                          e.printStackTrace ();
                      }
                  }
              }
              document.close ();
      
      

       

        Attachments

        1. test.pdf
          7 kB
          Thomas Gawehn

          Activity

            People

            • Assignee:
              tilman Tilman Hausherr
              Reporter:
              tgawehn Thomas Gawehn

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment