I am not understanding why Aspose Words using Times New Roman font behind the scenes even when I specify a font style in code, i.e., Calibri. I have checked my machine and all fonts are available → Windows.Fonts…
Sample code:
It seems that you are experiencing issues with Aspose.Words defaulting to the Times New Roman font even when you specify Calibri in your code. This can happen due to several reasons related to font availability and substitution settings.
Here are some steps you can take to ensure that your specified font is used correctly:
Font Settings Configuration: Make sure you are configuring the font settings properly. You can create an instance of FontSettings and specify the default font. If the specified font is not found, Aspose.Words will substitute it with the closest available font on your system.
Check Font Availability: Ensure that the Calibri font is installed and accessible on your machine. Sometimes, even if the font appears to be installed, there may be issues with its accessibility.
Font Substitution Mechanism: Aspose.Words uses a font substitution mechanism when the specified font cannot be found. You can check for font substitution warnings by implementing the IWarningCallback interface. This will help you identify if and why a substitution is occurring.
Clear Formatting: You mentioned trying builder.Font.ClearFormatting(). This is a good approach to ensure that no previous formatting is affecting the font settings. Make sure to call this method before setting the font name.
Version Changes: Since you mentioned that this issue did not occur in older versions of Aspose.Words, it might be worth checking the release notes for version 24.8.0 to see if there are any changes related to font handling that could affect your implementation.
By following these steps, you should be able to resolve the issue of Aspose.Words defaulting to Times New Roman instead of Calibri. If the problem persists, consider reaching out to the Aspose community for further assistance.
I can try this FallBack…
But the main problem here is that I can’t specify fonts and change/use them where needed…
What would be the rule and range for Calibri, using font size 10 in an xml file?
I tried the above and the fallback setting suggestion (separately), it still didn’t work. Document does have Calibri font displaying everywhere else correctly (so this is not font is inaccessible issue), except for this table.
@johnAxe Could you please attach your output document and provide runnable code that will allow us to reproduce the problem? We will check your scenario on our side and provide you more information.
I can’t include the document, documents generated can’t be shared with unauthorized parties. The code base is very large, and includes parts that can’t be shared with unauthorized parties, such as DB connections , licenses etc. I clearly see Calibri 10 everywhere in the document except for texts inserted in this table with code piece you see.
@johnAxe We need the code that will allow us to reproduce the problem on our side. Unfortunately, using the provided information we cannot reproduce the problem on our side. As shown above the font is properly set in the generated document.
I resolved this issue: builder.InsertHtml(cell_value, true);
Here, useBuilderFormatting needed to be set to true.
Please refer to this when your clients are having similar issue.