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

Free Support Forum - aspose.com

SVG elements in HTML to DOCX and HTML to PDF are not accessible

We have Aspose.Total license and we are using Aspose v21.7.0 for converting HTML to DOCX and PDF document.

We have few SVG’s inside the html file which is getting converted as image when converting it to WORD or PDF which is great. But all the accessibility properties are ignored and the images are not accessible.

We have 4 issues related to SVG out of which we feel 3 issues are bug and 4th one is likely a question or requesting for recommendation

  1. aria-hidden=“true” attribute is ignored and so the SVG / Images which we want to make it a decorative item is not achievable. Hence requesting you for an option to mark SVG’s and Images as decorative when converted from HTML.

  2. By setting focusable=“false”, we expect it not to be focused while navigation, but still it is getting focus. May be solving above issue could implicitly solve this as well.

  3. To make the SVG accessible, we are trying to provide the Title tag and still it is not applied as ALT text while generating the document.

  4. This is more likely a question rather than reporting as an issue. Currently when we provide margin in style tag for SVG element, it works fine with browser. But when same HTML is generated as DOCX, this margin is not applied. This could also be a limitation with DOCX / PDF, but would like to know if their is a workaround.

Note: All these issues are applicable for HTML to PDF conversion as well.

This is also reproducible with the online web version of Aspose converter if that would be simple to reproduce: https://products.aspose.app/words/conversion/html-to-word

Here is the sample HTML file with which we were able to reproduce the issue: SVH Test.zip (446 Bytes)

Here is the screenshot of the word document which shows the Accessibility issue: SVG Accessability Issue.png (30.2 KB)

Here is the sample code which we are using to convert the HTML to WORD programatically:

// This is an abstract of what we have in code

var inputStream = /* Stream of the html */
var doc = new Aspose.Words.Document(inputStream, new LoadOptions { Encoding = Encoding.UTF8 });

var filename = /* some docx file name */
var stream = new MemoryStream();
var saveOptions = SaveOptions.CreateSaveOptions(filename);

doc.Save(stream, saveOptions);

// Now stream contains the document

I know you have been doing great in terms of prompt reply / support. Any help is greatly appreciated and thank you in advance for the same.

@shridhartl As you may know DOCX format supports direct insertion of SVG images into the document. While converting the HTML document you have attached to DOCX Aspose.Words does insert SVG images as SVG into the DOCX document so all the properties are preserved in the resulting document, but MS Word seems does not respect the mentioned properties and they are ignored.
I suspect MS Word treats SVG images as a simple vector graphics and does not respect advanced SVG features. As a workaround you can postprocess your document and set the appropriate shape properties for example AlternativeText.