Hi,
Thank you for your inquiry.
I have tested the code and file you provided and encounter the same issue as you. However, there is another solution to achieve the effect you want, please refer to the following code and have a test:
- Code: Select all
var htmlContent = "Pommes Frites (Pommes frites (Kartoffeln, Rapsöl), HO Sonnenblumenöl, Speisesalz), Kalbfleisch (Kalbfleisch (Schweiz).), Gemüsemischung (Karotten, Blumenkohl, Bohnen grün, Zwiebeln, <strong>Butter</strong>, Petersilie glatt (mit Antioxidationsmittel: Milchsäure)), Panade-Mischung (Paniermehl (Hart<strong>weizen</strong>mehl, <strong>Weizen</strong>mehl, Hefe, Kochsalz jodiert.), <strong>Vollei </strong>flüssig, pasteurisiert, Bodenhaltung; Säuerungsmittel E330.), Mehlmischung (<strong>Weizen</strong>mehl, <strong>Hartweizendunst</strong>, <strong>Weizengluten</strong>, <strong>Gerstenmalzmehl</strong>)), Pflanzenöl (HO Sonnenblumenöl), Zitronen (Zitronen.)";
var document = new Document("TestHtml.docx");
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
bookmarkNavigator.MoveToBookmark("HTMLContent", false, true);
if (bookmarkNavigator.CurrentBookmark == null)
{
return;
}
var tempSection = document.AddSection();
tempSection.AddParagraph().AppendHTML(htmlContent);
var replacementFirstItem = tempSection.Paragraphs[0].Items.FirstItem as ParagraphBase;
var replacementLastItem = tempSection.Paragraphs[tempSection.Paragraphs.Count - 1].Items.LastItem as ParagraphBase;
var selection = new TextBodySelection(replacementFirstItem, replacementLastItem);
var part = new TextBodyPart(selection);
bookmarkNavigator.DeleteBookmarkContent(false);
bookmarkNavigator.ReplaceBookmarkContent(part,false,true);
document.Sections.Remove(tempSection);
document.SaveToFile(@"E:\34740\TestHtml4.docx", FileFormat.Docx);
document.SaveToFile(@"E:\34740\TestHtml4.pdf", new ToPdfParameterList { IsEmbeddedAllFonts = true });
This is my test screenshot:
屏幕截图 2023-10-07 172957.png
If you have any issue just feel free to contact us.
Sincerely,
Ula
E-iceblue support team
Login to view the files attached to this post.