Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in PDFBoxTree.java on line 391 - and fix #55

Open
perlausten opened this issue Jul 27, 2022 · 0 comments
Open

NullPointerException in PDFBoxTree.java on line 391 - and fix #55

perlausten opened this issue Jul 27, 2022 · 0 comments

Comments

@perlausten
Copy link

I have a PDF that results in a NullPointerException in PDFBoxTree.java on line 391 when trying to convert it. The reason is that the font variable is null.

The fix is to include a check for null before checking the font type.

for (COSName key : resources.getFontNames())
{
    PDFont font = resources.getFont(key);
    if (null != font) {
        if (font instanceof PDTrueTypeFont)
        {
            table.addEntry( font);
            log.debug("Font: " + font.getName() + " TTF");
        }
        else if (font instanceof PDType0Font)
        {
            PDCIDFont descendantFont = ((PDType0Font) font).getDescendantFont();
            if (descendantFont instanceof PDCIDFontType2)
                table.addEntry(font);
            else
                log.warn(fontNotSupportedMessage, font.getName(), font.getClass().getSimpleName());
        }
        else if (font instanceof PDType1CFont)
            table.addEntry(font);
        else
            log.warn(fontNotSupportedMessage, font.getName(), font.getClass().getSimpleName());
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant