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

Free Support Forum - aspose.com

Is it possible to convert an SVG graphic embedded in an html file into a PNG

Hey all,


We have some XHTML files that contain SVG graphics in them. The question is whether it is possible to rasterize these SVG graphics and save them to a PNG either in a stream or on the filesystem. The API we would like to use is Aspose.Words for Java, although Aspose.PDF might be an option as well.

According to some documentation we found, it seems that “Import of SVG images in HTML is supported”. However, there does not seem to be any statement that it is possible to save them to PNG.

According to the Aspose.PDF documentation, it is possible to save an SVG to a PDF, but would it be possible to save it to a PNG there as well?

Thanks for any help!

Similarly, would this work for Content MathML that is embedded in html? Is there any plan to add support for this if not? That is, can the visitor render the Content MathML to a PNG?


http://www.w3.org/Math/XSL/csmall2.xml

I wrote up some code to test the SVG case, and all I got was an empty, white PNG file generated.

Thanks!

Hi Chase,


Thanks for your inquiry. Please attach your sample XHTML/HTML documents here for testing. We will investigate the scenario on our end and provide you code to achieve this.

Best regards,

Hey awais.hafeez is not online. Last active: 08-04-2014, 8:01 AMAwais,


Attached you will find two HTML files that we would like to convert to PNG.

Thank you for any help!





Hi Chase,


Thanks for your inquiry.

For some reasons Aspose.Words 14.6.0 is not able to load these HTML files into DOM. I have logged the following two issues in our bug tracking system to address these problems.

WORDSNET-10560: System.Xml.XmlException occurs during loading Html into DOM (related to svg-ex.html)
WORDSNET-10561: System.Xml.XmlException occurs during loading Html into DOM (related to svg-ex2.html)

Your thread has also been linked to these issues and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Generally, once the HTML is loaded into Aspose.Words’ DOM, you can use the following code to convert all pages to PNG files:
Document doc = new Document(“C:\Temp\in.html”);

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
options.setPageCount(1);

// Save each page of the document as Png.
for (int i = 0; i < doc.getPageCount(); i++)
{
options.setPageIndex(i);
doc.save(“C:\Temp\out_” + i + “.png”, options);
}

I hope, this helps.

Best regards,

Thank you!


Particularly, we were wondering if the foreignObject tag in the SVG would be supported? Perhaps this is related to the problem?

Hi Chase,


Thanks for the additional information. Our development team has completed the analysis of theses issues and the root causes of these errors have been identified. We will inform you as soon as these issues are resolved. We apologize for any inconvenience.

Best regards,

The issues you have found earlier (filed as WORDSNET-10560;WORDSNET-10561) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.