NullPointerException with embedded TTF

Help
2012-06-25
2013-01-26
  • Aleksandr Smyshliaev

    Hello!

    While filling a PDF form, i get this exception:

    Exception in thread "main" java.lang.NullPointerException
            at java.util.Hashtable.put(Hashtable.java:437)
            at org.pdfclown.documents.contents.fonts.SimpleFont.onLoad(SimpleFont.java:139)
            at org.pdfclown.documents.contents.fonts.Font.load(Font.java:737)
            at org.pdfclown.documents.contents.fonts.Font.<init>(Font.java:351)
            at org.pdfclown.documents.contents.fonts.SimpleFont.<init>(SimpleFont.java:62)
            at org.pdfclown.documents.contents.fonts.TrueTypeFont.<init>(TrueTypeFont.java:69)
            at org.pdfclown.documents.contents.fonts.Font.wrap(Font.java:253)
            at org.pdfclown.documents.contents.FontResources.wrap(FontResources.java:64)
            at org.pdfclown.documents.contents.FontResources.wrap(FontResources.java:40)
            at org.pdfclown.documents.contents.ResourceItems.get(ResourceItems.java:158)
            at org.pdfclown.documents.interaction.forms.TextField.refreshAppearance(TextField.java:327)
            at org.pdfclown.documents.interaction.forms.TextField.setValue(TextField.java:218)
            at FillForm.fillForm(FillForm.java:38)
            at FillForm.main(FillForm.java:59)
    

    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.

     
  • Aleksandr Smyshliaev

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

     
  • Anonymous - 2012-06-28

    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

    zievereir - 2012-10-10

    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.

    SimpleFont.java
    if(code != null && glyphIndexes.get(code) != null)
                {
                  glyphWidths.put(
                    glyphIndexes.get(code),
                    glyphWidth
                    );
                }
    

    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!

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks