The character NNBSP is converted to wrong bytes if saved to PDF

I have a Word document with only the text 2 141 (the thousand separator is the NNBSP character U+202F).

When I convert the document to PDF using document.save(outputStream, SaveFormat.PDF);, then the NNBSP is converted correctly on my machine into the byes -30 -128 -81. But when the document is saved on the server, then the NNBSP character is converted into -17 -65 -65. As a consequence, the character is shown as a boxed cross in the PDF.

Our program is based on Java 21 and Aspose Word 25.1.

The text uses the font Roboto. If I change the font to Times New Roman, then the NNBSP character is converted to the correct bytes (the PDF itself uses the font DejaVuSans).

What can a font cause the difference in byte generation?

@bottemav Could you please attach your sample input and output PDF documents (both correct and incorrect)? We will check the issue and provide you more information.

@alexey.noskov
The template
OnlyTheNumber.docx (13.1 KB)

The generation on my machine
NNBSP-local.pdf (14.0 KB)

The generation on the server
NNBSP-server.pdf (7.4 KB)

I enabled the warning callback and on my machine, I get this warning “Font ‘Roboto’ has not been found. Using ‘Arial’ font instead. Reason: alternative name from document.” On the server, no warnings are logged.

I installed the font Roboto-Regular.ttf on my machine after which the warning disappears, and the PDF is still generated correctly:
NNBSP-local-after-font-installation.pdf (17.0 KB)

@bottemav It looks like Roboto font does not have the required glyph so it is rendered as missed glyph. If Aspose.Words cannot find the required glyph in the specified font, it tries to find this glyphs among other available fonts. This mechanism is called font fallback.

Arial font on other hand has the required glyph, so if install both Roboto and Arial fonts the document is rendered properly:
out.pdf (17.4 KB)

And the output document has both Roboto and Arial fonts:

@alexey.noskov Thanks for the quick support. I’ll check the font fallback.

1 Like