Styling CSS ::before Selector using insertHtml

Hi,

I’m trying to convert an HTML block including line numbers into word using Aspose words library.
I’ve added some CSS rule (::before selector) to highlight the line number section, but when I try to generate it using insertHtml it seems to not work correctly.
I attach a simple java application to be used in your test scenario. I also attach an image which shows my desired output.

Screen Shot 2019-01-29 at 22.05.34.png (64.5 KB)

aspose-html.zip (25.6 KB)

Regards,
Behrouz

@behrouz,

Please extract these HTML and CSS files inside a folder and then open HTMLPage1.html file with web browser:
HTML CSS.zip (1.2 KB)

Now, please open the HTMLPage1.html file with MS Word and convert it (Save As) to DOCX format. Then use the following code to convert this HTML to DOCX by using Aspose.Words.

Document doc = new Document("E:\\temp\\HTMLPage1.html");
doc.save("E:\\temp\\awjava-19.1.docx");

You will see MS Word 2019 and Aspose.Words 19.1 both do not respect all CSS elements during importing such HTML. Aspose.Words mimics the behavior of MS Word but in this case DOCX generated by Aspose.Words looks better.

See: MSW AW.zip (15.3 KB)
where msw-2019.docx is converted by using MS Word 2019 on our end and
awjava-19.1.docx is produced by Aspose.Words for Java 19.1 on our end.

So, it is not always guaranteed that the Aspose.Words generated output document will look exactly the same as the input HTML file shown in web browsers. This is because Aspose.Words was originally designed to work with Microsoft Word documents and HTML documents are quite different. Hope, this helps.

Please let us know if we can be of any further assistance.