MS Visio is a widely used application for creating large numbers of diagrams (e.g. flow charts, business flow charts, etc.). However, in various cases, you may need to convert the graph file to another file format. For example, when you share charts, you can convert them to PDF files. On the other hand, diagrams can also be converted into images for embedding in Web or desktop applications.

Aspose.Diagram for.net is a C# class library designed to learn from. NET application creates and manipulates MS Visio diagrams internally. In addition, it provides a high-fidelity converter API that allows you to convert Visio charts to PDF and other formats. (Download latest version)

In this article, you programmatically position a Visio chart as a PDF conversion. In particular, you’ll learn how to convert VSDX or VSD files to PDF using C#.

Convert Visio to PDF in C#

Here are the steps to convert a Visio Diagram to PDF using Aspose.Diagram for.NET.

  • Load Visio VSD or VDSX files using the diagram class.
  • Create a MemoryStream object.
  • Use the Diagram.Save (MemoryStream, savefileformat.pdf) method to convert the Visio file to PDF and Save it to a MemoryStream object.
  • Create a new FileStream object for the converted PDF file.
  • Save the converted PDF using the memoryStream.writeto (FileStream) method.
  • Disable MemoryStream and FileStream.

Below is the complete source code for converting Visio files to PDF using C#.

// Create a diagram object to load a VSD/VSDX diagram
Diagram diagram = new Diagram("Diagram.vsd");

// Create memory stream and save the diagram as PDF
MemoryStream pdfStream = new MemoryStream();
diagram.Save(pdfStream, SaveFileFormat.PDF);

// Create a PDF file
FileStream pdfFileStream = new FileStream("ExportToPDF.pdf", FileMode.Create, FileAccess.Write);
// Write to the file
pdfStream.WriteTo(pdfFileStream);

// Close streams
pdfFileStream.Close();
pdfStream.Close();
Copy the code

Below is a screenshot of the results obtained using the above code.

Visio diagram

Convert PDF

If you have any questions or requirements, please feel free to join the Aspose Technology Exchange Group (761297826), we are happy to provide you with inquiries and consultation.