The attached HTML file (“MissingBorder.html”) has an embedded PNG image and the <IMG> node uses the following border style attribute:
style='border:1px solid #ff0000 !important;
When the HTML file is rendered in any major browser, thin red border is shown. However, when inserted into a document via the DocumentBuilder.insertHtml API - the border disappears.
The following code demonstrates how to reproduce this behavior.
If you run the code (after adjusting the file path to the attached HTML file) - you should see that the Document generated will show the image but not the red border (that is shown in the browser).
MissingBorder.zip (6.9 KB)
final String htmlSrc = "[file_path]\MissingBorder.html"; try { // create new blank document Document wdDoc = new Document(); DocumentBuilder builder = new DocumentBuilder(wdDoc); // load the html final String html = new String(Files.readAllBytes(Paths.get(htmlSrc))); // add the paragraph to the document Paragraph para = builder.insertParagraph(); builder.moveTo(para); // insert the HTML into the doc - keep HTML formatting intact builder.insertHtml(html, false); wdDoc.save(htmlSrc.replace(".html", ".docx")); System.out.println("Saved Document: n\t" + htmlSrc.replace(".html", ".docx")); } catch (Exception ex) { System.out.println("Unexpected EXCEPTION: \n\t" + ex.getClass().getName() + " - " + ex.getMessage()); ex.printStackTrace(); } Thanks