We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Font substitution doesn't work with .mht

In order to test the font substitution, i have suppressed the Haettenschweiler font from then installed font directory on windows 10.
I set Arial Narrow as substitution font for Haettenschweiler in Aspose.words.

When i convert to pdf a .docx which uses Haettenscwheiler the Arial Narrow font is well used to replace Haettenschweiler

When i convert to pdf the attached .Mht which uses Haettenscwheiler too, the Haettenschweiler font is replaced by the standard replacement font, not by Arial Narrow …

Thanks in advance for your help.
message.zip (5.1 KB)

@tparassin,

Thanks for your inquiry. To ensure a timely and accurate response, please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. We will investigate the issue on our side and provide you more information.

attached is the sample program and 2 files :

  • test_fonts.docx : when converted to pdf, the missing HaettenSchweiler font is replaced by ComicSansMs as required in the sample program
  • message.mht : when converted to pdf, the missing HaettenSchweiler font is not replaced by ComicSansMs

DocToPdf.zip (15.0 KB)

@tparassin,

Thanks for sharing the detail. We have tested the scenario using latest version of Aspose.Words for .NET 18.8 and have not found the shared issue. So, please use Aspose.Words for .NET 18.8.

I am sorry but even with Aspose.Words 18.8, i still get the problem.
Do you suppress the HaettenSchweiler font from your Windows10 before to run the sample program ?

Attached are the 2 generated pdf files.
Temp.zip (99.1 KB)

@tparassin,

Could you please share the steps that you are using to reproduce this issue at our end? We will investigate the issue on our side and provide you more information.

I suppress the HaettenSchweiler font from the Windows installed fonts.
then i run the sample program on the attached .docx which uses HaettenSchweiler font ==> the created pdf contains the Comic sans MS font as substitution font for HaettenSchweiler
then i run the sample program on the attached .mht which uses HaettenSchweiler font ==> the created pdf doesn’t contain the Comic sans MS font but the standard substitution font

@tparassin,

Thanks for sharing the detail. We have removed the HaettenSchweiler font from Windows/Fonts folder and the execute the shared code. We have not found the shared issue.

Could you please put “Comic Sans MS” font into c:\temp folder, set the font folder as shown below, execute the code, and share the output PDF files here for our reference? We will investigate this issue further and provide you more information on it. Thanks for your cooperation.

FontSettings fontSettings = new FontSettings();
fontSettings.SetFontSubstitutes("HaettenSchweiler", new string[] { "Comic Sans MS" });
fontSettings.SetFontsFolder("c:\\temp\\", false);
doc.FontSettings = fontSettings;

attached is the output pdf files
Temp.zip (30.7 KB)

thanks for your support.

fyi, when i run the code on the .docx file, i get from the callback function
“Font substitution: Font substitutes: ‘Haettenschweiler’ replaced with ‘Comic Sans MS’.”
==> ok

and when i run it on the .mht file, i get
“Font substitution: Table column widths may need to be calculated. Rendered column widths could differ.
At Table 1, Section 1”
==> it seems there is a problem …

in my previous reply, i was using the initlal code i sent you, not the modified one.

@tparassin

Thanks for your inquiry. As per my understanding, you want to substitute ‘Haettenschweiler’ with ‘Comic Sans MS’. In this case, the font ‘Haettenschweiler’ should not exist in the font sources.

Please make sure that you have deleted the font “Haettenschweiler” from Windows/Fonts folder. Before converting your document to PDF, you can check the available fonts using the code example shared here:
How to Get Available Fonts for Rendering

yes, I confirm that I want to substitute ‘Haettenschweiler’ with ‘Comic Sans MS’ and that the font ‘Haettenschweiler’ DOESN’T exist in the Windows/Fonts folder.
You can double-check it as the Haettenschweiler font is not present in the resulting pdf files.

But when I convert the .mht file with the code I sent you, the substitution doesn’t use the ‘comic sans MS’ but the default font.
And in the callback log, i can see
“Table column widths may need to be calculated. Rendered column widths could differ.
At Table 1, Section 1”
which can explain with the substitution doesn’t use the Comic Sans MS font …

@tparassin

The shared PDF files use ‘Comic Sans MS’. We are really very sorry for your inconvenience but we are unable to reproduce the shared issue. Please try to restart your system and then execute the code and let us know if you still face problem.

of course, the shared pdf files use “Comic Sans MS” because they are the results of the test you ask me to do with “fontSettings.SetFontsFolder(“c:\temp\”, false);” and “comic sans MS” font in c:\temp.
And with this configuration, the only available font is Comic sans MS, then all the fonts in the pdf are Comic sans MS !

I underline my problem
With I run this code

Document doc = new Document("d:\\temp\\testfont.mht");
FontSettings fontSettings = new FontSettings();
fontSettings.SetFontSubstitutes("HaettenSchweiler", new string[] { "Comic Sans MS" });
doc.FontSettings = fontSettings;
doc.Save("d:\\temp\\testfont.pdf");

on the attached testfont.mht with the HaettenSchweiler font in the Windows fonts directory, I get the attached testfont1.pdf with the HaettenSchweiler font. it’s correct.

Then I suppress the HaettenSchweiler font from the Windows fonts directory and I run again the code where i ask the HaettenSchweiler font will be replaced by “Comic Sans MS” if missing.

I get the attached testfont2.pdf where the HaettenSchweiler font was replaced by “Arial MT” instead of “Comic Sans MS”.

Can you reproduce this test ?
testfont.zip (120.2 KB)

@tparassin

Thanks for sharing the detail. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17383. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@tparassin

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-17383) as ‘Not a Bug’.

Please use the latest version of Aspose.Words for .NET 19.4 and use following code example to get the desired output.

FontSettings fontSettings = new FontSettings();
TableSubstitutionRule substitutionRule = fontSettings.SubstitutionSettings.TableSubstitution;
// If "HaettenSchweiler" font is not available then substitute it by "Comic Sans MS".
substitutionRule.AddSubstitutes("HaettenSchweiler", new string[] { "Comic Sans MS" });
Aspose.Words.LoadOptions lo = new Aspose.Words.LoadOptions();
lo.FontSettings = fontSettings;
Document doc = new Document(MyDir + "testfont.mht", lo);

doc.Save(MyDir + "19.42.pdf");

does it mean the font substitution process has been modified and that we must use now TableSubstitutionRule ?

@tparassin

Yes, the substitution process has been modified. Please use the suggested code in my previous post and read the following article.
Font Availability and Substitution

The issues you have found earlier (filed as WORDSNET-17383) have been fixed in this Aspose.Words for .NET 19.5 update and this Aspose.Words for Java 19.5 update.