Convert docx to pdf (using dotnet in docker) has problem with some persian fonts specially IranNastaliq and some other persian fonts

Hi, I am using aspose.words version 23.12 to convert docx file to pdf. Everything is ok. There is only one problem. In files that use Persian fonts such as IranNastaliq, this font is not recognized and is seen differently from the original font. I have created a sample Word and PDF file and I am placing the Nastaliq font here. Of course, this problem also exists with some Persian fonts. I will you pictures of word docx file & converted pdf file.
converted pdf by aspose.words file pic

word file pic:

docx file:
ehdas - Copy.docx (25.6 KB)

http://www.fonts2u.com/irannastaliq.font

@mhdoosti By default MS Word uses advanced typograph features.
Advanced typography features are supported by Aspose.Words via Aspose.Words.Shaping.HarfBuzz nuget package.
You should install the above package and modify the code as shown below:

Document doc = new Document("in.docx"); 
// Configure shaping in order to support font kerning. 
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance; 
doc.Save("out.pdf");

See more about advanced typograph features in the documentation: https://docs.aspose.com/words/net/enable-opentype-features/

1 Like

Thanks alot
Yes this dll solve my problem.
I have another question. In dll document i see that its dependancy is .net framework 4.0. What this means. Does it mean that i cannot use this dll with .net framework 6.0?

(NuGet Gallery | Aspose.Words.Shaping.HarfBuzz 23.12.0)

And another problem; When i add harfbuzz dll to my project. I recieve error in convert docx to pdf

Error: Text shaper factory failed to return text shaper for ‘C:\Users\HP\AppData\Local\Microsoft\Windows\Fonts\IranNastaliq.ttf’, face index ‘0’
[Harfbuzz ]

@mhdoosti There is no .NET Framework 6.0, there is .NET 6.0, which is an evolution of .NET Core. .NET Core is an implementation of .NET Standard, so in .NET 6.0, the dll for .NET Standard is used.

For Windows platforms no additional efforts are required for installing HarfBuzz because Aspose.Words.Shaping.Harfbuzz already includes compiled HarfBuzz library.
For other systems, Aspose.Words.Shaping.Harfbuzz relies on already installed HarfBuzz library. For instance, many Linux-based systems have HarfBuzz installed system-wide by default. If not, there is usually a package available for installing via package manager.

Thankful. I can not get your point. What is the cause of this error? It means that if I run the same program in Linux, it will run without error??

@mhdoosti You should install libharfbuzz package into your Linux docker image. For example:

apt-get update && apt-get install -y libharfbuzz-dev

I will test it in docker. But now in windows and .net 6, aspose.words 23.6 & aspose.words.shaping.harbuzz 23.6 has not any error and run ok.
But with version 23.12 of aspose.words & 23.12 of aspose.words.shaping.harbuzz I recieve error
Error: Text shaper factory failed to return text shaper for ‘C:\Users\HP\AppData\Local\Microsoft\Windows\Fonts\IranNastaliq.ttf’, face index ‘0’
[Harfbuzz ]

@mhdoosti Unfortunately, I cannot reproduce the problem on my side. If possible, could you please create a simple console application that will allow us to reproduce the problem on our side. We will check it and provide you more information.

i migrate to linux. and after that my problem is solved by running this commang
apt-get update && apt-get install -y libharfbuzz-dev
thank you very much.

@mhdoosti Please install libharfbuzz in your docker image:

RUN apt-get update && apt-get install -y libharfbuzz-dev
1 Like