Articles in this section
Category / Section

Exporting with Different Option

3 mins read

Exporting Diagram with Different Option:

Syncfusion® Diagram supports exporting diagrams with different options. To export a diagram in A4 size, we need to initialize the diagram accordingly with the A4 size.

The below code snippet shows how to initialize the diagram with the desired A4 size.

[C#]

var sizeA4 = new PaperSize();
sizeA4.RawKind = PaperKind.A4;
// Initializing Diagram’s size.
diagram1.Size = new Size(sizeA4.Width, sizeA4.Height);

 

[VB]

Dim sizeA4 = New PaperSize()
sizeA4.RawKind = PaperKind.A4
‘Initializing Diagram’s size.
diagram1.Size = New Size(sizeA4.Width, sizeA4.Height)            

 

To export a diagram with bounds where the node is available, you need to set `true` for the `SizeToContent` property and set `false` for the `BoundaryConstraintsEnabled` property.

The below code shows how to export the diagram based on the bounds where the node is available.

[C#]

diagram1.Model.BoundaryConstraintsEnabled = false;
diagram1.Model.SizeToContent = true;

 

[VB]

diagram1.Model.BoundaryConstraintsEnabled = False
diagram1.Model.SizeToContent = True

 

To export diagram in image format the SaveFileDialog must be initialized and required image format must be passed as an argument.

The below code snippet show how to export the diagram in image format.

[C#]

SaveFileDialog saveFileDialog1 = new SaveFileDialog();
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    // To export the diagram in PNG format
    ImageFormat imgformat = ImageFormat.Png;
    Image img = this.diagram1.View.ExportDiagramAsImage(false);
    img.Save(saveFileDialog1.FileName, imgformat);
}

 

[VB]

Dim saveFileDialog1 As New SaveFileDialog()
            If saveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
              ‘To Export the diagram in PNG format
                Dim imgformat As ImageFormat = ImageFormat.Png
                Dim img As Image = Me.diagram1.View.ExportDiagramAsImage(False)
                img.Save(saveFileDialog1.FileName, imgformat)
            End If

 

Conclusion

I hope you enjoyed learning about exporting diagrams with different options..

You can refer to WinForms Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Diagram example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied