Free Support Forum - aspose.com

Render Thai language Text in DOCX to PDF using OpenType Features of Aspose.Words API

Hello,
My name is Mohamed and I’m a developer.
We use your library Aspose in my company, and today, we encountered a bug on PDF file generation in Thai language.
The generation of Word files works correctly, but the generation of PDF files has errors.
It seems to me that you have already identified this bug under reference WORDSNET-18424.

In our solution (.NET), we use:
- Aspose.Words (18.5.0.0).
- Aspose.PDF (18.5.0.0).

Could you please give us more information about this issue and how we can resolve it?


Best regards,
Mohamed.

@mhamitouche

Would you kindly share your sample PDF file along with sample code snippet that you are trying to generate PDF. We will test the scenario in our environment and address it accordingly.

Hello,
Thank you for responding very quickly.
Here is a simplified C# script that I use in my application:

using Aspose.Words;
namespace MhmTest
{
class Program
{
static void Main(string[] args)
{
string docxFilePath = @“C:\Users\mhm\Desktop\Template.docx”;
string pdfFilePath = @“C:\Users\mhm\Desktop\AsposeResult.pdf”;
var aWord = new Document(docxFilePath);
aWord.MailMerge.TrimWhitespaces = false;
aWord.BuiltInDocumentProperties.Author = “AuthorName”;
aWord.MailMerge.MergeDuplicateRegions = true;
aWord.Save(pdfFilePath, SaveFormat.Pdf);
}
}
}

N.B.:
Text inside Template.docx file is: ใบสั่งซื้อ

Thank you in advance!
Mohamed.

Word_OK.jpg (6.1 KB)
PDF_KO.jpg (14.0 KB)

@mhamitouche

Since you are using Aspose.Words, we are moving this thread to respective category where you will be assisted shortly.

@mhamitouche,

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document (Template.docx)
  • Aspose.Words for .NET 19.11 generated output PDF file (AsposeResult.pdf) showing the undesired behavior
  • Your expected DOCX file showing the desired output.
  • Please also create a standalone simple console application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

Hello,
You will find attached the standalone application you requested.
Thank you in advance!

Best regards.
Mohamed.

AsposePDF.zip (4.6 MB)

@mhamitouche,

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-19576. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

Hello,
Thank you for your reply.
I’m waiting for your answer.
Thanks in advance.
Mohamed.

@mhamitouche,

Your issue (WORDSNET-19576) is currently pending for analysis and is in the queue. We will inform you via this thread as soon as this issue will be resolved in future.

@mhamitouche,

Regarding WORDSNET-19576, it is to update you that Aspose.Words can now render such Thai language in this document correctly with the help of the HarfBuzz shaping engine. This requires installing the Aspose.Words.Shaping.Harfbuzz nuget package and adding an extra line of code:

var doc = new Document(@".\Template.docx");
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
doc.Save(@".\Template.pdf");

To learn more about OpenType features, please refer to the following article:

I just applied your correction, and visibly, it works well.
Thank you for your help, I’m grateful.

Best regards,
Mohamed.

@mhamitouche,

Thanks for your feedback. It is great that installing the Aspose.Words.Shaping.Harfbuzz nuget package and adding an extra line of code doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance; works for you.

In case you have further inquiries or need any help in future, please let us know.

Hello Hafeez,
After doing some tests, we discovered another bug:
"Text shaper factory failed to return text shaper for ‘C:\windows\Fonts\calibri.ttf’, face index ‘0’"
While searching the Internet, I did not find a solution.
Here is the file used:
Template.zip (76.7 KB)
By checking the Fonts available on my machine, everything seems correct.
Thank you in advance.
Mohamed.

@mhamitouche,

I am afraid, we do not see any issue when running the following code with Aspose.Words for .NET 19.11 and Aspose.Words.Shaping.HarfBuzz 19.11 on our end:

Document doc = new Document("E:\\Temp\\template\\template.docx");
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
doc.Save("E:\\Temp\\template\\19.11.pdf");

Please remove/uninstall Aspose.Words for .NET and Aspose.Words.Shaping.HarfBuzz from your Visual Studio project.
Then add reference to Aspose.Words for .NET 19.11 package (latest version)
And then add reference to Aspose.Words.Shaping.HarfBuzz 19.11 package (latest version)

Hope, this resolves your problem.

Hi,
Sorry for the delay, I was on vacation.
My script works when I set, in the properties of my VS project, this configuration:
Platform target: Any CPU. Prefer 32-bit.
or
Platform target: x86.

I’m on Windows 10, x64.

Mohamed.

@mhamitouche,

Can you please ZIP and attach a simplified Visual Studio project in which you are unable to add reference to Aspose.Words.Shaping.HarfBuzz 19.11 package via NuGet? Thanks for your cooperation.

Hi,
Find attached the requested Console application:
AsposePDF.zip (9.6 MB)

Working configuration:
Aspose_AnyCPU_Prefer_32-bit.jpg (31.0 KB)

Thank you in advance.
Mohamed.

@mhamitouche,

When running your project, we have managed to observe the following error on our end.

  • Text shaper factory failed to return text shaper for ‘C:\WINDOWS\Fonts\calibri.ttf’, face index ‘0’

In the “Solution Explorer”, right click “AsposePDF” project and choose “Manage NuGet Packages”. In the “Updates” tab, you will see Aspose.Words entry. Updating Aspose.Words to 19.12 version will also update the “Aspose.Words.Shaping.HarfBuzz” to 19.12. Rebuild the project and Run it. It should work now.

Hello,
Thank you for your availability.
Looking in NuGet repository, it seems to me that the version 19.12.0 of Aspose.Words.Shaping.HarfBuzz does not exist.
To see here:

Aspose.Words.Shaping.HarfBuzz 19.11.0 is not compatible with Aspose.Words 19.12.0.
I had this error at installation:

Unable to resolve dependencies. ‘Aspose.Words 19.12.0’ is not compatible with ‘Aspose.Words.Shaping.HarfBuzz 19.11.0 constraint: Aspose.Words (= 19.11.0)’.

After that, I installed Aspose.Words.Shaping.HarfBuzz 19.11.0 by disabling dependencies (NuGet > Options > Ignore Dependencies).

Now, with Aspose.Words 19.12.0 and Aspose.Words.Shaping.HarfBuzz 19.11.0 installed, I have no more errors with Any CPU and x64 target platform configs, but I have the same error like before with x86 and Any CPU Prefer 32-bit target platform config.

I’m on Windows 10, 64-bit.

@mhamitouche,

We have just published Aspose.Words.Shaping.HarfBuzz 19.12 version on NuGet. We tested it on our end and it worked fine along with Aspose.Words for .NET 19.12 even in x86 and Any CPU Prefer 32-bit target platform configuration.

So, please upgrade to Aspose.Words for .NET 19.12 and Aspose.Words.Shaping.HarfBuzz 19.12 and see how it goes on your end? Hope, this helps.