Search
Exporting the Diagram

Export Bitmap Images

You can create a bitmap image representing the current diagram using the CreateImage method. The method returns a Microsoft.Maui.Graphics.IImage instance. The following example shows how to export a diagram to a Png image file :

C#  Copy Code

var image = diagram.CreateImage();
image.SaveAsync(stream, ImageFormat.Png);

The MindFusion.Diagramming.Export Namespace contains classes for exporting to Dxf, Pdf, Svg, Wmf, Swf and Visio formats.

Export DXF files

Add a reference to the MindFusion.Diagramming.Export.dll to your project. Create a DxfExporter instance and call its Export method, specifying a Diagram object and a file path as arguments. Raster images can be used in DXF by referencing external image files. To export the images displayed in diagram elements, enable the ExportImages property. If your application supports the multiple-line text DXF entity - MTEXT, use the ExportTextAsMultiline property. The following example shows how to create a DxfExporter instance and export a diagram:

C#  Copy Code

var dxfExporter = new MindFusion.Diagramming.Export.DxfExporter();
dxfExporter.Export(diagram, exportPath + "diagram.dxf");

Export PDF files

Add a reference to the MindFusion.Diagramming.Export.dll to your project. Create a PdfExporter instance and call its Export method. Margins specifies the page margins for all pages in the document. If you need to set the page size and orientation, use the PageSize, and PageOrientation properties. The AutoScale property allows scaling the diagram to fit in one or more PDF pages. If invisible items should be displayed in the PDF, enable the InvisibleItems property. The following example shows how to export a diagram to PDF:

C#  Copy Code

var pdfExporter = new MindFusion.Diagramming.Export.PdfExporter();
pdfExporter.Export(diagram, exportPath + "diagram.pdf");

Export SVG files

Add a reference to the MindFusion.Diagramming.Export.dll to your project. Create an SvgExporter instance and call its Export method, passing a Diagram object and either a file path or stream as parameters.

C#  Copy Code

var svgExporter = new MindFusion.Diagramming.Export.SvgExporter();
svgExporter.Export(diagram, exportPath + "diagram.svg");

Export Visio files

Add a reference to the MindFusion.Diagramming.Export.dll to your project. Create a new instance of the VisioExporter class and call its Export method passing a Diagram object and the full path to the exported Visio .vdx file as parameters. The exporter requires the VisioExport.vxt file to be present in the application's directory or the path specified by TemplatePath. This file contains an XML template data used by the component to generate Visio documents.

ShapeNode objects are mapped to their closest Visio counterparts and DiagramLink instances are exported as Visio connectors of a similar style. In addition, most of the attributes of diagram items such as text, text formatting, fill and line colors and styles are preserved.

TableNode objects are exported as groups of Visio shapes or as Entity shapes. If TableNodes should be exported as groups of Visio rectangular shapes, enable the ExportTablesAsGroups property.

C#  Copy Code

var visioExporter = new VisioExporter();
visioExporter.Export(diagram, exportPath + "diagram.vdx");

Export Excel files

The ExcelExporter class from MindFusion.Diagramming.Export.dll assembly exports diagrams to Excel Open XML Format (XLSX) files. Diagrams are exported as Excel AutoShapes drawings. The Export overload that takes a DiagramDocument parameter creates a sheet for each DiagramPage in the document. The Export(Diagram) overload creates a single Excel sheet.