Preserving source font and size when adding text with HtmlLoadOptions()

Hi,

I am merging some fields in a DOCX document. Some of my fields contain HTML code that I handle with a custom “Html” prefix and process in document.MailMerge.FieldMerging event.

Unfortunately, when the merge is performed, I lose the source font formatting defined in the DOCX file with the one in the HTML fragment inserted in the document (which is normal behavior).

How can I use backup the source field font and apply back after calling:

 e.Field.Content.End.LoadText((string)e.Value, new GemBox.Document.HtmlLoadOptions());

Thanks.

Hi Omid,

Try this:

var options = new HtmlLoadOptions() { InheritCharacterFormat = true, InheritParagraphFormat = true };
e.Field.Content.End.LoadText((string)e.Value, options);

Does it solve your issue?

Regards,
Mario

Hi Mario,
Thanks for you answer. I don’t see those properties in the HtmlLoadOptions class :frowning: . In which version did you add those properties?
Thanks,
Omid.

Hi Omid,

They were introduced in the GemBox.Document 3.3 version 1155 which was released on 2021-03-15.

Regards,
Mario

Hi,

Unfortunately I have a pre version: 33.0.310.1108 from february 2021 :frowning:. I’ll test when I’ll upgrade the version.

Thanks.