Search
Exporting the Diagram

Exporting Bitmap Images

You can create a static image representing the current diagram using the CreateImage method. The method returns an instance of the System.Drawing.Bitmap class. The following example shows how to export a diagram to a Png image file in response to pressing a button, using the SaveFileDialog control where the location is selected and the name of the image file is entered:

C#  Copy Code

private void btnPngExport_Click(object sender, System.EventArgs e)
{
    saveFileDialog.DefaultExt = "png";
    saveFileDialog.Filter = "PNG files|*.png";
    if (saveFileDialog.ShowDialog() == DialogResult.OK)
    {
        Image image = diagram1.CreateImage();
        image.Save(saveFileDialog.FileName);
        image.Dispose();
    }
}

Visual Basic  Copy Code

Private Sub btnPngExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPngExport.Click

    saveFileDialog.DefaultExt = "png"
    saveFileDialog.Filter = "PNG files|*.png"
    If saveFileDialog1.ShowDialog() = DialogResult.OK Then
        Dim image As Image = diagram1.CreateImage()
        image.Save(saveFileDialog1.FileName)
        image.Dispose()
    End If

End Sub

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

Exporting to DXF files

Add a reference to the MindFusion.Diagramming.Export.Dxf.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 by performing the Export method passing the Diagram object and the file name entered in a SaveFileDialog.

C#  Copy Code

MindFusion.Diagramming.Export.DxfExporter dxfExp = new MindFusion.Diagramming.Export.DxfExporter();
dxfExp.Export(diagramView1.Diagram, saveFileDialog.FileName);

Exporting to Pdf files

Add references to the MindFusion.Diagramming.Export.Pdf.dll and MindFusion.Pdf.dll assemblies 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 a Pdf file in response to pressing a button event and using the SaveFileDialog control where the location is selected and the name of the Pdf file is entered:

C#  Copy Code

private void button1_Click(object sender, EventArgs e)
{
    saveFileDialog.DefaultExt = "pdf";
    saveFileDialog.Filter = "PDF files|*.pdf";
    if (saveFileDialog.ShowDialog() == DialogResult.OK)
    {
        MindFusion.Diagramming.Export.PdfExporter pdfExp = new MindFusion.Diagramming.Export.PdfExporter();
        pdfExp.Export(diagramView1.Diagram, saveFileDialog.FileName);
    }
}

Visual Basic  Copy Code

Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click

    saveFileDialog.DefaultExt = "pdf"
    saveFileDialog.Filter = "PDF files|*.pdf"
    If saveFileDialog.ShowDialog() = DialogResult.OK Then
        pdfExp.Export(diagramView1.Diagram, saveFileDialog.FileName)
    End If

End Sub

Dim pdfExp As New MindFusion.Diagramming.Export.PdfExporter

Exporting to Svg files

Add references to the MindFusion.Diagramming.Export.Svg.dll and MindFusion.Svg.dll assemblies to your project. Create an SvgExporter instance and call its Export method, passing a Diagram object and the full path to the .svg file as parameters. To export images displayed by diagram items to external files, enable the ExternalImages property.

C#  Copy Code

MindFusion.Diagramming.Export.SvgExporter svgExp = new MindFusion.Diagramming.Export.SvgExporter();
svgExp.ExternalImages = false;
svgExp.Export(diagramView.Diagram, saveFileDialog.FileName);

Visual Basic  Copy Code

Dim svgExp As MindFusion.Diagramming.Export.SvgExporter = _
     New MindFusion.Diagramming.Export.SvgExporter()
svgExp.ExternalImages = False
svgExp.Export(diagramView1.Diagram, saveFileDialog.FileName)

Exporting to Visio files

Add a reference to the MindFusion.Diagramming.Export.Visio.dll to your project. The NetDiagram ShapeNode objects are mapped to their closest Visio counterparts and TableNode objects are exported as groups of Visio shapes. NetDiagram 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.
The exporter object requires the VisioExport.vxt file to be present in the application's directory. This file contains an XML template data used by the component to generate Visio documents.
Create a new instance of the VisioExporter class. Call the Export method passing a Diagram object and the full path to the exported Visio .vdx file as parameters. The Visio page dimension and items size measure unit is set to the diagram's MeasureUnit.
To create Visio groups from the NetDiagram groups, enable the CreateVisioGroups property. If a shape node that contains an image should be exported as a Visio group of a shape, picture and text objects, use the ExportImagesAsGroups property set to true by default. ExportInvisibleItems allows exporting of invisible items. If NetDiagram TableNode objects should be exported as groups of Visio rectangular shapes, enable the ExportTablesAsGroups property.

The following example shows how to export a diagram to a Visio file in response to choosing a File > Export to > Visio menu item and using the SaveFileDialog control where the location is selected and the name of the Visio file is entered:

C#  Copy Code

private void _menuItemExportVisio_Click(object sender, System.EventArgs e)
{
    SaveFileDialog dlg = new SaveFileDialog();

    dlg.Filter = "Visio files (*.vdx)|*.vdx|All files|*.*||";

    if (dlg.ShowDialog(this) == DialogResult.OK)
    {
        VisioExporter export = new VisioExporter();
        export.Export(_diagram, dlg.FileName);
    }
}

Exporting WMF images

Add a reference to the MindFusion.Diagramming.Export.Wmf.dll assembly to your project. Create a WmfExporter instance and call its Export method, passing a Diagram object and the full path to the .wmf file as parameters.

Exporting Adobe Flash files

Add a reference to the MindFusion.Diagramming.Export.Swf.dll assembly to your project. Create an SwfExporter instance and call its Export method, passing a Diagram object and the full path to the .swf file as parameters.

Export Excel files

The ExcelExporter class from MindFusion.Diagramming.Export.Excel.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.