We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Character Style is not Imported into DOM | HTML to PDF Conversion using Java

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)

@benjamin.schueller

We have tested the scenario and managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-22488. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Thanks a lot. But i’m wondering why it is a WORDSNET-Ticket. I’m using Java. Shouldn’t it be WORDSJAVA? Or do i misunderstood something?

@benjamin.schueller

Please note that the latest version of Aspose.Words for Java is completely auto-ported from .NET, i.e. we do not write code for Aspose.Words for Java; it is generated out automatically from C# code of Aspose.Words for .NET.

In your case, the issue which was logged with WORDSNET prefix, would be auto resolved for Java variant of Aspose.Words. Your problem WORDSNET-22488 will be fixed in ‘Aspose.Words for Java’ as soon as the linked issue will get resolved.