I’m generating a Word document using the same template on both Windows and Unix environments using Aspose Build Report in Java. The Word documents are generated correctly in both environments, with all characters rendered properly.
However, when generating PDF from the same template:
On Windows: The PDF is generated correctly, with all characters displayed as expected.
On Unix (Docker): The PDF contains question marks (?) in place of certain characters.
For the Unix environment, I’m using the Amazon Corretto (Java) Docker image as the base. After debugging, I found that the PDF generated in this environment is missing the Calibri font which causes the incorrect rendering. (Screenshots attached)
Also when I manually copied the Calibri font into the Corretto Docker image using a Dockerfile (Steps screenshots attached), the PDF was generated correctly with all characters rendered properly.
Since the Word document renders fine in both environments (Windows and Unix (Amazon Corretto Docker Image), the expectation is that PDF generation should also handle fonts consistently.
Attached:
The template, input-data and generated Word and PDFs documents from both Windows and Unix environments.
Screenshots highlighting the issue in the Unix-generated PDF
Dockerfile snippet showing font installation.
Execution_of_Font_Issue.zip (320.5 KB)
@harika1231 Most likely the problem occurs because the fonts are not available on the machine where the document is converted to PDF. If Aspose.Words cannot find the fonts used in the document the fonts are substituted. This might lead into the layout differences due to differences in fonts metrics. You can implement IWarningCallback to get a notification when font substitution is performed.
The following articles can be useful for you:
https://docs.aspose.com/words/java/specify-truetype-fonts-location/
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/
If the required fonts are missing, why does the Word document render correctly, but the issue only appears in the generated PDF? Shouldn’t the Word output also reflect the same problem?
@harika1231 MS Word uses the fonts available in the user’s environment unless the fonts are embedded into the document.
If you check the attachment, you’ll notice inconsistencies in how characters are rendered in the generated PDF. Some characters appear correctly in certain sections but are missing or not displayed properly in others.
For example:
In the table, only the character ‘A’ is rendered correctly, while the others are missing.
The same characters appear as expected outside the table.
Even in the evaluation warning, some characters are shown properly, while others are not.
Could you suggest possible reasons for this inconsistency?
@harika1231 As mentioned above the problem occurs because the fonts required to render the document are not available. If you check the fonts used in the output PDF documents you have attached you will notice the differences. To get consistent rendering result on different platforms the same set of fonts must be available on these platforms.
You should also note that fonts might not have all glyphs, in this case font fallback mechanism is applied, i.e. Aspose.Words (the same as MS Word) looks for the required glyphs among the available fonts.
Was checking the documented example for font substitution, as per example we are setting default as Arial, but then why Calibri is getting used
@alexey.noskov And also what is diff between substitution font setting and fallback setting?
@harika1231
Font substitution process consists of several rules which are checked one by one in specific order. If the first rule can’t resolve the font then second rule is checked and so on.
The order of the rules is following:
- Font name substitution rule (enabled by default)
- Font config substitution rule (disabled by default)
- Table substitution rule (enabled by default)
- Font info substitution rule (enabled by default)
- Default font rule (enabled by default)
So in your case even if you set default substitution font as Arial
it does not mean that Arial
font will be used to render the document since other substitution rules might be applied before. Also if Calibri
font is available font substitution for this font is not performed at all.
If font specified in the original document is not available in the environment where the document is rendered, font substitution is performed, i.e. Aspose.Words tries to find an alternative font using rules listed above.
In the font used for rendering does not contain some glyph required for rendering, Aspose.Words uses font fallback mechanism, i.e. tries to find font that contains the required glyph. For example many fonts does not contain glyphs for Chinese hieroglyphs and in this case Aspose.Words uses glyphs from the fallback font, SimSun
for instance.
And is there any way to force substitute font to particular font, like Any font which is not available in doc then use Some default font (Eg: Calibri) as for IWarningCallback it is returning description, which font substituted by similar font?
@harika1231 Warning description shown by IWarningCallback
contains information about font substitution and rule which was applied. You can configure font substitutions using FontSubstitutionSettings.
@alexey.noskov Is there any way by which we can implement fallback mechanism similar to substitution and how?
@harika1231 Sure, you can use FontFallbackSettings to configure fallback settings.
@alexey.noskov Sry for confusion, I want to say, implementation of fallback warning, like substitution warning
@harika1231 No unfortunately, there is no way to get warnings about font fallback.
@alexey.noskov Could we please implement warning whenever font fallback is happening?
We are required to report font fallback events also along with font substitution
@harika1231
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-24619
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.