Does Aspose Word. NET support HTML encoding

Hi all,

I want to insert text that contains HTML tags (e.g. <br />) into a document via Aspose Word .NET. Does it support HTML encoding?

Thanks in advance!

Hi

Thanks for your interest in Aspose. Of course you can do it with Aspose.Words. Please try using the following code:

// Create document and DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert HTML using InsertHtml method
builder.InsertHtml("<b>This<br />is Bold Text.</b>");
doc.Save("out.doc");

Best regards,

Thanks! It works!

Hi,

The HTML encoded text works, but the formatting is lost. Below is the sample:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.Font.Size = 11;

builder.Font.Bold = true;

builder.Font.Color = System.Drawing.Color.Blue;
builder.Write(  "Summary" );
//The formatting below is lost
builder.Font.Name =  "Arial" ;
builder.Font.Size = 11;
builder.Font.Bold =  false ;
builder.Font.Color = System.Drawing.  Color .Brown;

builder.InsertHtml(  "This <br/> is <strong>Bold Text</strong>." );

doc.Save(MapPath(  "Html.doc" ));

How to specify font formatting for HTML encoded text (font type and font size are required)?

It seems the system default font size is calibri, 11. How to change the system default font type and font size?

Thanks in advance.

Hi

Thank you for additional information. The content inserted by Insert HTML does not inherit formatting specified in DocumentBuilder options. Whole formatting is taken from HTML snippet.
But you can try using the workaround provided by Adam in this thread:
https://forum.aspose.com/t/53489
Regarding second question, you can change default font type and style using the following code:

doc.Styles["Normal"].Font.Name = "Arial";
doc.Styles["Normal"].Font.Size = 11;
doc.Styles["Normal"].Font.Bold = false;
doc.Styles["Normal"].Font.Color = System.Drawing.Color.Brown;

Best regards,