NullPointerException with embedded TTF

  • Hello!

    While filling a PDF form, i get this exception:

    Exception in thread "main" java.lang.NullPointerException
            at java.util.Hashtable.put(
            at org.pdfclown.documents.contents.fonts.SimpleFont.onLoad(
            at org.pdfclown.documents.contents.fonts.Font.load(
            at org.pdfclown.documents.contents.fonts.Font.<init>(
            at org.pdfclown.documents.contents.fonts.SimpleFont.<init>(
            at org.pdfclown.documents.contents.fonts.TrueTypeFont.<init>(
            at org.pdfclown.documents.contents.fonts.Font.wrap(
            at org.pdfclown.documents.contents.FontResources.wrap(
            at org.pdfclown.documents.contents.FontResources.wrap(
            at org.pdfclown.documents.contents.ResourceItems.get(
            at org.pdfclown.documents.interaction.forms.TextField.refreshAppearance(
            at org.pdfclown.documents.interaction.forms.TextField.setValue(
            at FillForm.fillForm(
            at FillForm.main(

    The error comes from the very first widths entry, i.e. charCode is FirstChar (zero).  Code lookup gives 65533, which is not in the glyphIndexes table.  Maximum code present in glyphIndexes is 65532.

    Is there anything I can do to avoid this error?  The PDF file with the form that I have to fill comes from outside my company.

  • Update: there would be the same failure for all characters in range 0-31 and for character 152.


  • Anonymous

    Am also having the same issue with SimpleFont where I have multiple codes not in the glyphIndexes Map.  I am trying to render a PDF to an image.

  • zievereir

    I also stumbled on this NullPointerException while parsing PDFs. I'm using PDF Clown to parse PDFs and to highlight text and my highlighting process always failed when this Exception occured. I got around it by editing the PDF Clown sources, I added a null check on glyphIndexes.get(code) in order to avoid having my highlighting process being disrupted.
    if(code != null && glyphIndexes.get(code) != null)

    I'm mainly just reading through PDF's so I'm not sure if this happens to have an impact on writing a PDF, but for me at least this does the trick.

    Thanks for the great library btw!