You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Thomas Gawehn (Jira)" <ji...@apache.org> on 2020/06/12 14:22:00 UTC

[jira] [Updated] (PDFBOX-4878) Call to Dictionary.encoding throws NullPointerException for some PDF's

     [ https://issues.apache.org/jira/browse/PDFBOX-4878?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Gawehn updated PDFBOX-4878:
----------------------------------
    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):

 

 
{code:java}
        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 ();

{code}
 

  was:
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):

{{{{}}}}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);
 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 ();

{{}}{{ }}


> Call to Dictionary.encoding throws NullPointerException for some PDF's
> ----------------------------------------------------------------------
>
>                 Key: PDFBOX-4878
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4878
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.20
>            Reporter: Thomas Gawehn
>            Priority: Critical
>         Attachments: test.pdf
>
>
> 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):
>  
>  
> {code:java}
>         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 ();
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org