Insert html in Run?

Hi,

Is it possible to insert html in run (paragraph)??

Run run = new Run(doc, textToInsert);
run.Font.Style = doc.Styles["PFS_DATA"];
run.Font.Color = Color.Black;
para.AppendChild(run);

cell.AppendChild(para);
row.AppendChild(cell);
table.AppendChild(row);

Actually, the variable “textToInsert” is a plain text, but our client wants to insert html text. Is it possible to do that?? Or do you have a workaround to be able to insert html??

Thank you

Steeve

Hi Steeve,

Thanks for your inquiry. Yes, you can insert html at the place of Run node in a Paragraph of document. Please note that, content inserted by DocumentBuilder.InsertHtml** method does not inherit formatting specified in DocumentBuilder options. Whole formatting is taken from HTML snippet. If you insert HTML with no formatting specified, then default formatting is used for inserted content.

Please use the following code snippet to insert html at Run node. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
Paragraph para = doc.FirstSection.Body.FirstParagraph;
Run run = new Run(doc, "");
para.AppendChild(run);
builder.MoveTo(run);
builder.InsertHtml(
    "<P align='right'>Paragraph right</P>" +
    "<b>Implicit paragraph left</b>" +
    "<div align='center'>Div center</div>" +
    "<h1 align='left'>Heading 1 left.</h1>");
doc.Save(MyDir + "out.docx");