pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivan Pavlyukovets <Ivan_Pavlyukov...@epam.com>
Subject problem with "No glyph for U+%04X in font %s"
Date Mon, 10 Oct 2016 10:36:32 GMT

I have a little problem with pdf file generation using PDFBox 2.0.3 and I can't find ways
to solve it ...

I have a string which is generated by using random unicode symbols (Symbol 'U+22F2' is presented
in the string for example.)
and take the following exception when make some actions with this string:
Caused by: java.lang.IllegalArgumentException: No glyph for U+22F2 in font ArialUnicodeMS
                at org.apache.pdfbox.pdmodel.font.PDCIDFontType2.encode(PDCIDFontType2.java:401)
                at org.apache.pdfbox.pdmodel.font.PDType0Font.encode(PDType0Font.java:351)
                at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:316)
                at org.apache.pdfbox.pdmodel.PDPageContentStream.showText(PDPageContentStream.java:414)

It's happened when I try to embed "Arial Unicode MS" font.
I tried to find this "wrong" symbols by using org.apache.pdfbox.pdmodel.font.PDType0Font#hasGlyph
but I saw that this symbol has glyph (It's allowed in  Identity-H encoding which is used for
embedded fonts).

I see that a lot of methods use PDCIDFontType2.encode and it has strange behavior ...
It has the following block which throw exception if cid has 0 value
                if (cid == 0)
            throw new IllegalArgumentException(
                    String.format("No glyph for U+%04X in font %s", unicode, getName()));
I read in  https://www.microsoft.com/typography/otspec/cmap.htm that "Character codes that
do not correspond to any glyph in the font should be mapped to glyph index 0. The glyph at
this location must be a special glyph representing a missing character, commonly known as
When I deleted this block everything work fine and I saw special glyphs in generated pdf.

Steps to reproduce:
1. Create document
                PDDocument document = new PDDocument();
2. load Arial Unicode MS font:
                PDType0Font pdfFont = PDType0Font.load(document, document.getClass().getResourceAsStream("/ttf/arialuni.ttf"));
3. be sure that symbol has glyph
                int codePoint = 0x22F2;
4. catch strange exception
                PDCIDFontType2 pdcidFontType2 = (PDCIDFontType2)pdfFont.getDescendantFont();

Do you have any suggestions to solve this problem or should I create new issue?

Example is attached.

Ivan Pavlyukovets

View raw message