Issue with Converting Word to PDF with Thai font

Hi,

We use the below code to convert the Word document into PDF document. But found that Thai characters are not represented correctly in generated output. What was wrong with the below code which causes convertion incorretly? and what would be the solution?

I have attached my input (.docx) and output (.pdf) files here along with the picture highlighting what is the exact issue. Also attached the screenshot of Font availability in Fonts folder.

Aspose.Words.Document doc = new Aspose.Words.Document(@"C:\temp\original2.docx");
doc.Styles.DefaultFont.Name = "Arial";

FindReplaceOptions options = new FindReplaceOptions();
options.Direction = FindReplaceDirection.Forward;
options.MatchCase = false;
options.FindWholeWordsOnly = true;
//options.ReplacingCallback = new WordDocReplaceHandler();

doc.Range.Replace("Variable.text1", "ศรีนิวาส");

ReportingEngine oRE = new ReportingEngine();
oRE.BuildReport(doc, new DataTable());

MemoryStream outPDFStream = new MemoryStream();
doc.Save(outPDFStream, SaveFormat.Pdf);
byte[] pdfBytes = outPDFStream.ToArray();
outPDFStream.Close();

string outputPath = @"C:\temp\output.pdf";

using (FileStream oSourceStream = File.Create(outputPath))
{
    oSourceStream.Seek(0, SeekOrigin.End);
    oSourceStream.Write(pdfBytes, 0, pdfBytes.Length);
}

output.pdf (154.0 KB)

original2.docx (12.3 KB)

@srinudhulipalla The problem occurs because by default MS Word uses font open type features. Aspose.Words.Shaping.Harfbuzz package provides support for OpenType features in Aspose.Words using the HarfBuzz text shaping engine. You should enabling open type features to get the expected result. To achieve this you should add reference to Aspose.Words Shaping Harfbuzz plugin and use the following code to convert your document:

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

Hi,

Thank you very much. It works in sample console/desktop applicaiton and getting error in ASP.NET WebForm application which is hosted in IIS.

Unable to load DLL harfbuzz: The specified module could not be found. (Exception from HRESULT: 0x8007007E)-Text shaper factory failed to return text shaper for C:\WINDOWS\Fonts\arial.ttf, face index 0

Am I missing anything here? Here is the pic of Arial font in C:\Windows\Fonts\ :

@srinudhulipalla Which version of Aspose.Words do you use? There were issues with harfbuzz in older versions of Aspose.Words. The problem has been fixed in 23.2 version. The problem was the following:

Nuget package contains two native harfbuzz.dll compiled for x86 and x64 platforms and special MSBuild script.
Depending on project’s target platform, the MSBuild script chooses necessary native harfbuzz.dll (x86 or x64) and copies them to TargetDir of the project.

This MSBuild script detects project’s target platform using {PlatformTarget} and {Prefer32Bit} parameters of the project. It is mostly OK for all types of projects except ASP.NET WebForms.
Project’s target platform may depend on {Use64BitIISExpress} parameter of the project.
In general, there is no good way to detect actual project’s target platform if {Use64BitIISExpress} set to “Default” and {PlatformTarget} set to “Any CPU”.

The workaround: Please try to set explicit value in {Use64BitIISExpress} = x86 or x64. And REBUILD the project.

Hi @alexey.noskov

I am using Aspose.Words v23.11.0 and had the reported issue. But as you mentioned the reported issue is fixed in 23.2 version, I am not sure why still I get the error in that case.

Even if I am on v23.11 version, do I need to follow the work arround solution you have provided? If not, how do I troubleshoot what is the issue as I am already on latest version?

@srinudhulipalla Please make sure harfbuzz.dll is deployed properly. From the provided error message it looks like the dll is missed.