SVG to EMF conversion loses border and background color

Hi Team,

I am trying to convert an SVG to EMF using Aspose Words v21.7 library. The SVG has some border and background color applied to it and using the library to convert it to EMF loses the styles in the output.

Sample Code:

byte[] bytes = Files.readAllBytes("BarChart.svg");
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
final String svg = new String(bytes, StandardCharsets.UTF_8);
builder.insertHtml(svg, false);
    
double margin = 0;
PageSetup pageSetup = builder.getPageSetup();
pageSetup.setLeftMargin(margin);
pageSetup.setRightMargin(margin);
pageSetup.setTopMargin(margin);
pageSetup.setBottomMargin(margin);

double imgWidth = ConvertUtil.pixelToPoint(350);
double imgHeight = ConvertUtil.pixelToPoint(250);
pageSetup.setPageWidth(imgWidth);
pageSetup.setPageHeight(imgHeight);

//Save the Document as DOCX format - The converted document contains border and bgColor
final OoxmlSaveOptions docx = new OoxmlSaveOptions();
doc.save(filePathAndName + ".docx", docx);

//Save the Document as EMF format - This conversion does not have the border and bgColor
final ImageSaveOptions emfOptions = new ImageSaveOptions(SaveFormat.EMF);
doc.save(filePathAndName + ".emf", emfOptions);

Any idea what is happening during the conversion? How do I retain the border and bgColor in the EMF?

@oraspose
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-25199

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thanks for the bug details. Is their an alternative way to fix this issue?

@oraspose Unfortunately, there is no workaround of this issue using Aspose.Words.
As I can see your requirement is to convert SVG to EMF. You can consider using Aspose.Imaging to achieve this.

Hi @alexey.noskov, I was going through the ASPOSE Words Java documentation to find any information about the supported CSS Style properties that an can carry when inserting them into the Document but unfortunately I could not find it.

Would you be able share the documentation link or any information?

@oraspose Unfortunately there is no such detailed list. You can get the basic information here:
https://docs.aspose.com/words/java/document-features-supported-on-html-import/

In general you can export the document to HTML, all CSS attributes which are in the exported HTML are supported by Aspose.Words on HTML import.

@oraspose We have completed analysis of the issue. Aspose.Words doesn’t support “border” and “background-color” CSS properties upon loading SVG images. We aren’t going to implement this feature in Aspose.Words, because MS Word doesn’t support it either. If insert the provided SVG image into a document in MS Word, the result will be the same. We are going to close this issue with the “Won’t Fix” resolution.

Thank you for checking.

1 Like

The issues you have found earlier (filed as WORDSNET-25199) have been fixed in this Aspose.Words for .NET 23.5 update also available on NuGet.