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

Free Support Forum - aspose.com

Convert SVG Based Charts in HTML to DOCX using Java & Retain Text Baseline when Inserting HTML with SVG Charts to DOCX


We import SVG-based Charts into a Document via the DocumentBuilder.insertHtml method (link). We’ve noticed that in some cases, text elements within the SVG are not aligned properly. Specifically, it seems the dominant-baseline attribute is being ignored.

For example, if you render the attached svg_chart.html file in any major Browser, you should see that all the text elements (Chart Title and Legend) align properly. But when the same HTML file is imported into a Word document, the text elements are shifted upwards - as shown in the attached svg_chart_Aspose.docx document. Specifically, it seems the following attribute is being ignored by Words: dominant-baseline="text-before-edge"

This can be reproduced using the latest Aspose Words for Java version 20.1, the attached svg_chart.html file and the following code:

final String htmlSrc = [PATH] + "svg_chart.html";

// create new blank document
Document wdDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(wdDoc);

// add a new paragraph to the end of the doc
Paragraph para = new Paragraph(wdDoc);

// load & insert the HTML into the doc - keep HTML formatting intact
String html = new String(Files.readAllBytes(Paths.get(htmlSrc)), "UTF-8");
builder.insertHtml(html, false);

final String newDoc = htmlSrc.replace(".html", "_Aspose.docx");

System.out.println("Saved Document:  " + newDoc);

Environment information:

  • Aspose Words for Java version 20.1
  • Java Version 1.8.0_77
  • OS: Windows 10

Thank you.


We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-19887. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.


Regarding WORDSNET-19887, it is to update you that we have completed the analysis of this issue but I am afraid, the implementation of this issue has been postponed till a later date. The issue occurs because Aspose.Words currently does not support the “dominant-baseline” SVG attribute. Unfortunately, there are no estimates available at the moment. But we will inform you via this thread as soon as this feature will be implemented in future. We apologize for any inconvenience.

Awais - Thanks for the update and feedback. We will monitor the thread for updates.