Styling of bullets in lists imported from HTML

Hello,
I have a document that contains several text placeholders, each using different styles. At runtime, I need to replace these placeholders with HTML content, such as bulleted lists. While the styling of the inserted list items correctly matches the placeholder text, the bullet symbols themselves always use a different style that relies on the SymbolMT font. I want the bullets to inherit the same styling as the placeholder text and avoid using SymbolMT. The only solution I’ve found so far is to iterate over the newly created paragraphs and replace their ListFormat.ListLevelFormat.CharacterFormat with the formatting from the paragraph itself, then explicitly set the bullet symbol via ListFormat.ListLevelFormat.NumberFormat. Here’s a simplified snippet of the code I’m using:

var replacedRange = document
     .Content.Find("html")
     .FirstOrDefault()
     .LoadText(
         "<ul><li>Coffee</li><li>Tea</li><li>Milk</li></ul>",
         new HtmlLoadOptions()
         {
             InheritCharacterFormat = true,
             InheritParagraphFormat = true
         }
     );

 var htmlRange = new ContentRange(
     replacedRange.Start.Parent.Parent.Content.Start,
     replacedRange.End.Parent.Parent.Content.End
 );

 foreach (
     Paragraph paragraph in htmlRange.GetChildElements(
         [GemBox.Document.ElementType.Paragraph]
     )
 )
 {
     var listFormat = paragraph.ListFormat.ListLevelFormat;
     if (paragraph.ListFormat.IsList && listFormat.NumberStyle == NumberStyle.Bullet)
     {
         listFormat.CharacterFormat =
             startParagraph.ParagraphFormat.Style.CharacterFormat.Clone();
         listFormat.NumberFormat = "•";
     }
 }

Now, when I insert a bulleted list using Word anywhere in the (up-)loaded document, the bullets automatically adopt the styling of the list items, even though I haven’t modified the list style of the DefaultParagraphFormat.

This is the resulting PDF (the second list was inserted via Word):

How can I prevent this behavior?

Also, is there an alternative way to avoid using the SymbolMT font for bullets without manually replacing the displayed bullet symbol each time?

Thank you very much in advance.

Hi,

I want the bullets to inherit the same styling as the placeholder text and avoid using SymbolMT.

Unfortunately, that’s not supported.
However, perhaps you would be interested in explicitly specifying the bullet font inside your HTML.
In other words, you would read the current font that’s used by the placeholder content, add a certain CSS style in your HTML, and then import it.

Would that work for you?
Let us know, and we’ll investigate this idea further.

The only solution I’ve found so far is to iterate over the newly created paragraphs and replace their ListFormat.ListLevelFormat.CharacterFormat with the formatting from the paragraph itself

Yes, that is a decent workaround, but you just replace the font instead of replacing the whole CharacterFormat:

listFormat.CharacterFormat.FontName = startParagraph.ParagraphFormat.Style.CharacterFormat.FontName;

Now, when I insert a bulleted list using Word anywhere in the (up-)loaded document, the bullets automatically adopt the styling of the list items, even though I haven’t modified the list style of the DefaultParagraphFormat.

Can you explain this a bit more?
Can you also send us a sample document that demonstrates this behavior?

Regards,
Mario

Hello Mario,

thank you very much for the quick response. Setting just the name of the font and not the whole CharacterFormat for the bullets in lists created from HTML fixed the issue that other lists in the docx document, which were created manually via Word and not programmatically, suddenly had a different font for their bullets.