I’m trying to insert a small html-snippet using insertHtml
and convert the document to pdf. The html-snippet has a span-element in the middle with a class which points to a given word-character-style. The middle text is formatted as it should. But the text after the span does also have this formatting. But this shouldn’t be.
Given HTML: <p>One <span class="Strong">Two</span> Three</p>
Expected result: One Two Three
Given Result: One Two Three
My Code:
InputStream wordStream = InsertFormattedHtmlToBookmark.class.getResourceAsStream("wordTest1.docx");
Document wordDocument = new Document(wordStream);
DocumentBuilder documentBuilder = new DocumentBuilder(wordDocument);
documentBuilder.moveToBookmark("test", true, true);
String html = "<p>One <span class=\"Strong\">Two</span> Three</p>";
documentBuilder.insertHtml(html, true);
wordDocument.save("C:/TMP/test.pdf", SaveFormat.PDF);
wordTest1.docx (11.9 KB)