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

Free Support Forum - aspose.com

Text font is incorrect after inserting HTML into document using C#

Hi,

I am working on a C# Project where I need to Insert HTML into Word document and the functionality is working Fine using Aspose Word.

The major Issue I am facing with applying Template Styles and Font. What I have observed is that after loading the Template into the document object the Styles of Template are not been retrieved and the default font in the document are shown as Times New Roman.

Note: We have defined our Own Custom Styles in the template document.

Thanks,

Vasu

@Vasudeva.dammalapati

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

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

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.

PS: To attach these resources, please zip and upload them.

Hi Tahir,

I have attached the Console Application which will use template and insert HTML into the newly generated document.
In the template you can find the Table of contents font is Arial and after generation of the new document the font is showing as Times New Roman. Same with headers also. After generation we click on header 1 then correct font is coming up.

let me know if you still need any additional information.

Thanks,
vasuGenerateDocument - Demo.zip (111.7 KB)

@Vasudeva.dammalapati

Please use DocumentBuilder.InsertHtml method to insert an HTML string into the document. When second parameter is true, formatting of inserted text is based on DocumentBuilder formatting, and the text looks as if it were inserted with Write.

When second parameter is false, DocumentBuilder formatting is ignored and formatting of inserted text is based on default HTML formatting. As a result, the text looks as it is rendered in browsers.

Please use following line of code to get the desired output.

builder.InsertHtml((string)args.FieldValue, true);