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

Free Support Forum - aspose.com

Use Shaping.HarfBuzz to Render Telugu in Word Document to PDF using Gautami Font in C# .NET

Hi,

Text formatted with Gautami font in docx files has an issue when converted to PDF using .NET Standard version of Aspose.Words 19.5 (used in conjunction with Aspose.PDF 19.5).

I attached the following files in Gautami.zip (168.5 KB):

  1. Input - Gautami.docx: the input file that contains text formatted with the attached gautami.ttf font (that was installed on the system)

  2. Output - Gautami.docx - Aspose.pdf: what Aspose is generating with the code:

    var doc = new Document(input);

    doc.AcceptAllRevisions();

    doc.UpdateFields();

    doc.UpdatePageLayout();

    var saveFormat = new PdfSaveOptions
    {

     OptimizeOutput = true,
     ImageCompression = PdfImageCompression.Jpeg,
     
    
     PreserveFormFields = true,
    
     UpdateFields = true,
     SaveFormat = SaveFormat.Pdf
    

    };

    doc.Save(output, saveFormat);

  3. Output - Gautami.docx - Acrobat.pdf: what Acrobat Word plugin is generating when converting the input to PDF

The output generated by Aspose is different although the preview for that font in Windows shows the fine and confirms that it has no issues with any char in the input file.

Can you please help us understand what happens there and possibly point us to a workaround/solution?

Best regards,
Alin

@gwert,

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-19100. 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.

@gwert,

Regarding WORDSNET-19100, we are able to render your document correctly by using the Aspose.Words.Shaping.HarfBuzz package. So, please install this package and use the OpenType Features for proper rendering to PDF. Hope, this helps.

Happy New Year!

We have a follow-up issue related the fix for WORDSNET-19100.
We confirmed that the issue is fixed when checked on a Windows 10 machine with version 20.1 of both Aspose.Words and Aspose.Words.Shaping.HarfBuzz (installed through NuGet).

The following exception is what we get on the Hosted VS2017 machine in the Azure Pipeline CI build we set up just for the purpose of checking that the output of conversion is an actual PDF file:

System.AggregateException: One or more errors occurred. —> System.Exception: Text shaper factory failed to return text shaper for ‘C:\windows\Fonts\arialbd.ttf’, face index ‘0’ —> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at .(IntPtr , UInt32 , , IntPtr , IntPtr )
at .(String , Int32 )
at …ctor(String , Int32 )
at .()
at .( ? , Int32 , Boolean , Boolean )
at .( ? , Int32 , Boolean , Boolean )
at ?? . ()
at ?? .(?? , Int32 )
at ?? .(?? , Int32 )
at .(?? )
at .(?? )
at .()
at .( )
at .( ? )
at ?? .( ? )
at ?? .( ? )
at ?? .()
at ? .()
at Aspose.Words.Document.UpdatePageLayout()
at ZenQms.FileFormatApi.Conversion.WordsConverter.FileToPdf(String fileExtension, Stream input, Stream output) in d:\a\1\s\FileFormatApi\FileFormatApi\Conversion\WordsConverter.cs:line 31
at ZenQms.FileFormatApi.Converter.FileToPdf(String fileName, Stream inputFileStream, Stream outputPdfStream) in d:\a\1\s\FileFormatApi\FileFormatApi\Converter.cs:line 24
at ZenQms.FileFormatApi.Tests.Fixtures.BaseFixture.ConvertAndLoadAsPdf(String inputFileName) in d:\a\1\s\FileFormatApi\FileFormatApi.Tests\Fixtures\BaseFixture.cs:line 71
at ZenQms.FileFormatApi.Tests.ConverterTests.b__5_1() in d:\a\1\s\FileFormatApi\FileFormatApi.Tests\ConverterTests.cs:line 98
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
— End of inner exception stack trace —
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
at ZenQms.FileFormatApi.Tests.ConverterTests.b__5_0() in d:\a\1\s\FileFormatApi\FileFormatApi.Tests\ConverterTests.cs:line 234
at Xunit.Record.Exception(Action testCode) in C:\Dev\xunit\xunit\src\xunit.core\Record.cs:line 25
—> (Inner Exception #0) System.Exception: Text shaper factory failed to return text shaper for ‘C:\windows\Fonts\arialbd.ttf’, face index ‘0’ —> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at .(IntPtr , UInt32 , , IntPtr , IntPtr )
at .(String , Int32 )
at …ctor(String , Int32 )
at Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.GetTextShaper(String fontPath, Int32 faceIndex)
at Aspose.Words.Shaping.BasicTextShaperCache.uedky9tzt7pxzykqlqq44tu42twqvjcp ? (String , Int32 )
at .(? , ITextShaperFactory )
— End of inner exception stack trace —
at .(? , ITextShaperFactory )

The C:\windows\fonts folder could not exist on those machines but the machine definitely has a font repository that Apose components should just use by default, right?

Have you seen this issue before? This is critical to us as our conversion libraries are part of a dockerized service running on .NET Core on an non-Windows machine. We currently have no issues with fonts in the docker image.

Thank you!

@gwert,

Thanks for your feedback on WORDSNET-19100.

Regarding the exception you mentioned in previous post, we have logged a separate issue to investigate it on our end. The ID of this issue is WORDSNET-19855. We will further look into the details of this problem and will keep you updated on the status of this new issue. We apologize for your inconvenience.

@gwert,

Regarding WORDSNET-19855, the message “System.BadImageFormatException: An attempt was made to load a program with an incorrect format.” means that the process’s bitness does not match to harfbuzz dll bitness i.e. x64-bit process is trying to load x86-bit harfbuzz.dll (or vise versa). Please replace harfbuzz dlls on dockerized service with correct bitness (taking from .nuget package).

P.S. You can also manually add reference in your project. Please open Aspose.Words.Shaping.HarfBuzz and click on the Download package. Rename the .nupkg to .zip and extract the ZIP file. Inside the ~/runtimes folder you will find win-x64 and win-x86 folders. Depending upon the platform target (x86, x64), please copy the DLL files from correct folder to inside the Debug folder of your application. Hope, this helps.

This work, Thank you.