Search code examples
javapdffontspdfbox

PDFBox: No glyph for U+0050 in extracted font


I'm trying to create new page in document and write some text to it, while using the font contained in the file.

The font is extracted from the resources:

PDPage page = document.getPage(0);
PDResources res = page.getResources();

List<PDFont> fonts = new ArrayList<>();

for (COSName fontName : res.getFontNames()) {
     PDFont font = res.getFont(fontName);
     System.out.println(font);
     fonts.add(font);
}

And later used to write some text:

stream.beginText();
stream.setFont(fonts.get(0), 12);
stream.setTextMatrix(Matrix.getTranslateInstance(20, 50));
stream.showText("Protokol");
stream.endText();

The showText method always fails with error

No glyph for U+0050 (P) in font QZHBRL+ArialMT

But the glyph is there, as verified by FontForge: enter image description here

Also the method hasGlyph returns true.

The complete project including the PDF is available at github repository showing the issue


Solution

  • This has been fixed in issue PDFBOX-5103. This will be available in PDFBox 2.0.23 and until then, in a snapshot build.