Issue with thai text

Hello,

I’m testing the new version of Aspose.Words 26.1 and have found an issue with thai text.
I’m opening a docx file then define the font folder source for Aspose and save the document as pdf.
The result document shows boxes instead of the actual text.
When using the same code with version 25.2 the pdf document looks fine.
Can you please help me to solve the issue?

Here is the document and the font I load in Aspose for the thai text.
Thai Test.docx (13.9 KB)

Fonts.zip (72.0 KB)

And here the result documents made with Aspose version 26.1 and 25.2
Thai Test - Result with Asp261.pdf (34.6 KB)

Thai Test - Result with Asp252.pdf (48.4 KB)

@cternek

You reported an issue with Thai text rendering in Aspose.Words 26.1, where Thai characters appear as boxes in the generated PDF, while the same code worked correctly in version 25.2 . This could be due to changes in font handling or text rendering logic between these versions .

This type of issue has been previously observed with Thai text in Word to PDF conversions using Aspose.Words , suggesting it might relate to how the library handles Thai language fonts or character mapping in newer versions .

To help resolve this issue, we recommend:

  1. Ensure that all required Thai fonts are properly loaded into Aspose.Words using FontSettings and FontSourceBase .
  2. Try setting the font explicitly for Thai text content in your document before conversion.
  3. If possible, test with a minimal reproducible example to isolate whether the issue is with specific fonts or general Thai text handling.

A support engineer will follow up in this thread if more information is needed.

@cternek By default for Thai text Aspose.Words uses Browallia New font, you can check this by saving font fallback settings to XML:

FontSettings.DefaultInstance.FallbackSettings.Save(@"C:\Temp\FallbackSettings.xml");

In your case it is required to use Angsana New font for Thai text. To achieve this you can either try rebuilding font fallback settings automatically:

FontSettings.DefaultInstance.FallbackSettings.BuildAutomatic();

Or updating the appropriate entry in FallbackSettings.xml and loading it into font settings.

The following code produces correct output with your font:

FontSettings.DefaultInstance.SetFontsFolder(@"C:\Temp\fonts1", true);
FontSettings.DefaultInstance.FallbackSettings.BuildAutomatic();

Document doc = new Document(@"C:\Temp\in.docx");
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
doc.Save(@"C:\Temp\out.pdf");

fonts1 folder contains Angsana New and Arial fonts. Here is the produced output: out.pdf (48.5 KB)

Thank you for your code example
With your code example it works.

I used the function SetFontsSources to set the font folder instead of SetFontsFolder.
The thai font is not shown when I use that function with your code example.
Here is my code to set the folder:

  List<Aspose.Words.Fonts.FontSourceBase> fontbase = Aspose.Words.Fonts.FontSettings.DefaultInstance.GetFontsSources().ToList<Aspose.Words.Fonts.FontSourceBase>();

  fontbase.Add(new Aspose.Words.Fonts.FolderFontSource("C:\\_temp\\Fonts", true));

  Aspose.Words.Fonts.FontSettings.DefaultInstance.SetFontsSources(fontbase.ToArray<Aspose.Words.Fonts.FontSourceBase>());

Can you please help me to solve this issue?

@cternek The code looks correct and should work as expected. By default there is only one SystemFontSource. So you can modify your code like this

FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[] { new SystemFontSource(), new FolderFontSource(@"C:\Temp\fonts", true) });

When I use it that way, the thai text is displayed as boxes in the pdf.
Here is my code and the output pdf.

 Aspose.Words.Fonts.FontSettings.DefaultInstance.SetFontsSources(new Aspose.Words.Fonts.FontSourceBase[] { new Aspose.Words.Fonts.SystemFontSource(), new Aspose.Words.Fonts.FolderFontSource("C:\\temp\\Fonts", true) });
 Aspose.Words.Fonts.FontSettings.DefaultInstance.FallbackSettings.BuildAutomatic();
 
 doc = new Aspose.Words.Document(@"C:\Temp\in.docx");
 
 doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
 
 aspDoc.Save(@"C:\Temp\out.pdf");

out.pdf (34.6 KB)

@cternek As I can see in the attached PDF document there is only Arial font, but Angsana New is not used. Please make sure the Angsana New font is available in the specified font sources.

@alexey.noskov
The font folder contains the Angsana New font file.
I’ve sent the font file in my initial post.
The problem seems to be the function SetFontsSources.

It seems that the function SetFontsSources doesn’t load or find the Angsana New font file.
Please note that I use .Net Framework 4.6.2.

It doesn’t work when using this code line:

Aspose.Words.Fonts.FontSettings.DefaultInstance.SetFontsSources(new Aspose.Words.Fonts.FontSourceBase[] { new Aspose.Words.Fonts.SystemFontSource(), new Aspose.Words.Fonts.FolderFontSource("C:\\Temp\\Fonts", true) });

out SetFontSources.pdf (34.6 KB)

If I use this line of code instead, like in your example, it works fine.

Aspose.Words.Fonts.FontSettings.DefaultInstance.SetFontsFolder("C:\\Temp\\Fonts", true);

out SetFontsFolder.pdf (26.5 KB)

@cternek Please try using the following method to check what fonts Aspose.Words sees in the specified font sources:

/// <summary>
/// Prints the fonts available in the specified font settings.
/// </summary>
public static void PrintAvaialbleFonts(FontSettings fs)
{
    foreach (FontSourceBase fsb in fs.GetFontsSources())
    {
        Console.WriteLine(fsb.Type);
        foreach (PhysicalFontInfo pfi in fsb.GetAvailableFonts())
        {
            Console.WriteLine(pfi.FullFontName);
        }
        Console.WriteLine("================================================");
    }
}

Here is the output of both variants
fontinfos.zip (3.0 KB)

The code I used for the test is:

 Aspose.Words.Fonts.FontSettings.DefaultInstance.SetFontsFolder("C:\\Temp\\Fonts", false);
 PrintAvaialbleFonts(Aspose.Words.Fonts.FontSettings.DefaultInstance);

and

 Aspose.Words.Fonts.FontSettings.DefaultInstance.SetFontsSources(new Aspose.Words.Fonts.FontSourceBase[] { new Aspose.Words.Fonts.SystemFontSource(), new Aspose.Words.Fonts.FolderFontSource("C:\\Temp\\Fonts", true) });
 PrintAvaialbleFonts(Aspose.Words.Fonts.FontSettings.DefaultInstance);

@cternek Most likely when you use FallbackSettings.BuildAutomatic() Aspose.Words pics some other font from the System font source. Please try saving FallbackSettings to XML:

FontSettings.DefaultInstance.FallbackSettings.Save(@"C:\Temp\FallbackSettings.xml");

Then edit the XML file by changing this line:

<Rule Ranges="0E00-0E7F" FallbackFonts="Browallia New" />

with this one

<Rule Ranges="0E00-0E7F" FallbackFonts="Angsana New" />

Then load the resulting XML back:

FontSettings.DefaultInstance.FallbackSettings.Load(@"C:\Temp\FallbackSettings.xml");

@alexey.noskov
Thank you, that was helpful.
Aspose selects Cascadia Code font for some reasons.

<Rule Ranges="0E00-0E7F" FallbackFonts="Cascadia Code" />

Changing the order of the font sources solves the issue.
Thanks

1 Like