Home > Code > C# > C# & VB.NET Code Samples for Exporting MS Visio VSD Diagram to PDF

C# & VB.NET Code Samples for Exporting MS Visio VSD Diagram to PDF

by sher azam   on Dec 03, 2013   Category: C#   |  Views: 3379    |  Points: 25   |  Gold 

This technical tip shows how .NET developers can export Microsoft Visio diagram to PDF inside their own applications using Aspose.Diagram for .NET. Aspose.Diagram for .NET allows reading and creating diagrams as well as lets developers export diagrams to a variety of formats: XML formats, image formats, HTML, SVG, SWF and PDF. This tip explains how to export a Microsoft Visio diagram to PDF using Aspose.Diagram for .NET. Use the Diagram class' constructor to read the diagram files and the Save method to export the diagram to any supported image format. The image below shows the VSD diagram that the code snippets below export PDF. You can use other diagram formats (VSS, VDX, VST, VDX, VTX or VSX) as well.

Export VSD diagram to PDF:

• Create an instance of the Diagram class.
• Call the Diagram classs Save method and set the output format to PDF.

The Sample code shows how to export diagrams to a variety of formats


//Call the diagram constructor to load diagram from a VSD file
Diagram diagram = new Diagram("D:\\Drawing1.vsd");

MemoryStream pdfStream = new MemoryStream();
diagram.Save(pdfStream, SaveFileFormat.PDF);

byte[] pdfContent = pdfStream.GetBuffer();

this.Response.Charset = "UTF-8";
this.Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Response.ContentType = "application/pdf";
this.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.pdf");


'Call the diagram constructor to load diagram from a VSD file
Dim diagram As New Diagram("D:\Drawing1.vsd")

Dim pdfStream As New MemoryStream()
diagram.Save(pdfStream, SaveFileFormat.PDF)

Dim pdfContent() As Byte = pdfStream.GetBuffer()

Me.Response.Charset = "UTF-8"
Me.Response.ContentEncoding = System.Text.Encoding.UTF8
Me.Response.ContentType = "application/pdf"
Me.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.pdf")

Overview: Aspose.Diagram for .NET

Aspose.Diagram is a class library for working with MS Visio files & is a pure .NET alternate for MS Visio Object Model. It enables developers to work with VSD & VDX files on ASP.NET web applications, web services & Windows applications. It makes use of the advanced functionality of Visio's services to manipulate Visio docs on a server. Developer can open files & manipulate the elements of the diagram, from lines and fills, to more complex elements, and then export to native Visio formats or XML.

More about Aspose.Diagram for .NET

- Homepage of Aspose.Diagram for .NET: http://www.aspose.com/categories/.net-components/aspose.diagram-for-.net/default.aspx

- Download Aspose.Diagram for .NET: http://www.aspose.com/community/files/51/.net-components/aspose.diagram-for-.net/default.aspx

Post Code  |  Code Snippet Home

User Responses

No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts