List elements not shown in document with LoadText


I am trying to load Html content with the LoadText option. It seems to ignore lists “

” etc.
When using mailmerge with the html:fieldnames (as per your examples) they do work.

The code that I am trying:

// Code ommitted, but adding a new Paragraph to a section in a DocumentModel        

section.Blocks.Add(doc.AddHtmlParagraph("Here the content with the lists that dont get rendered in the Word file"));

        private static Paragraph AddHtmlParagraph(this DocumentModel doc, string content)
            var style = (ParagraphStyle)doc.Styles.GetOrAdd(StyleTemplateType.Normal);
            var p = new Paragraph(doc) { ParagraphFormat = { Style = style } };
            p.Content.Start.LoadText(content, new HtmlLoadOptions
                InheritCharacterFormat = true,
                InheritParagraphFormat = true,
                PreserveUnsupportedFeatures = true,
                HtmlType= HtmlType.Html,
            return p;

Any help would be appreciated. Due to the complex template the customer wants, using mailmerge would be a more difficult solution.



In GemBox.Document list items are represented with paragraphs. Your solution is loading HTML into a paragraph and since you cannot have a paragraph within a paragraph, HTML lists don’t get parsed as expected.

In order to get the desired behavior you need to load the HTML into a Section.Content or DocumentModel.Content. Here is an example:

var doc = new DocumentModel();
doc.Content.End.LoadText("<ul><li>A</li><li>B</li></ul>", new HtmlLoadOptions()
    InheritCharacterFormat = true,
    InheritParagraphFormat = true,
    PreserveUnsupportedFeatures = true,
    HtmlType = HtmlType.Html

I hope this helps.


Thanks Marko for another great solution!