Convert Visio to HTML format
Export Visio to HTML Export Visio to HTML
This article explains how to export a Microsoft Visio diagram to HTML using Aspose.Diagram for Java API.
Use the Diagram class constructor to read the diagram files and the Save method to export the diagram to any supported image format. Developers can save resultant HTML in the local storage or directly to a stream instance.
The image below shows a VSD file about to be saved to PNG format. You can use other diagram formats (VSDX, VSTM, VSTM, VSSX, VSS, VSSM, VDX, VST, VSTX, VDX, VTX or VSX) as well.
Input diagram.
In order to export VSD diagram to HTML, perform the following steps:
- Create an instance of the Diagram class.
- Call the Dagram class' Save method and set HTML as the output format.
The image below shows the output HTML file.
Output HTML diagram.
Save resultant HTML in the local storage
The resultant file can be saved by passing a complete path string, including the filename and extension, e.g. @“c:\temp\MyOutput.html”.
Save Resultant HTML in Local Storage Programming Sample
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ExportToHTML.class); | |
// call the diagram constructor to load diagram from a VSD file | |
Diagram diagram = new Diagram(dataDir + "ExportToHTML.vsd"); | |
// Save as HTML | |
diagram.save(dataDir + "ExportToHTML_Out.html", SaveFileFormat.HTML); |
Save resultant HTML in a stream instance
It is for use case to save the resultant HTML in a database or repository without storing it in the local storage. This feature also embeds other resultant resources of the HTML, e.g. fonts, CSS (containing the style information) and images. Since it saves a single HTML file into the stream instance.
Save Resultant HTML in a Stream Programming Sample
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ExportHTMLinStream.class); | |
// load diagram | |
Diagram diagram = new Diagram(dataDir + "ExportToHTML.vsd"); | |
// save resultant HTML directly to a stream | |
ByteArrayOutputStream dstStream = new ByteArrayOutputStream(); | |
diagram.save(dstStream, SaveFileFormat.HTML); | |
// In you want to read the result into a Diagram object again, in Java you need to get the | |
// data bytes and wrap into an input stream. | |
ByteArrayInputStream srcStream = new ByteArrayInputStream(dstStream.toByteArray()); |