We can use C# to programmatically print VSDX, DWG, VDW, VSTX, and other chart documents. The Aspose.Diagram for.NET API can be integrated into.NET based applications to process Microsoft Visio files. Refer to the following use case print chart documentation:

  • Print Visio documents programmatically using XpsPrint using C#
  • Print Visio charts programmatically to the default printer in C#
  • Print Visio diagrams programmatically to a specific printer using C#

We can print Visio shapes and diagrams in VSD, VSDX, DWG, and many other supported file formats using Aspose.Diagram for.net. Download the latest version Aspose.Diagram

Print Visio documents programmatically using XpsPrint using C#

The XpsPrint class is useful for printing chart files on server-side applications because the service does not support printing classes using the.NET Framework. The following steps explain how to programmatically print Visio documents using XpsPrint using C# :

  • Use Aspose.Diagram to convert the document to XPS and store it in the memory stream.
  • Send the chart document to the printer using the XpsPrint API.

The following code shows how to print a Visio document by sending it to a printer using the XpsPrint API:

public static void Print(Diagram diagram, string printerName, string jobName, bool isWait)
{
    if (diagram == null)
        throw new ArgumentNullException("document");

    // Use Aspose.Diagram to convert the document to XPS and store in a memory stream.
    MemoryStream stream = new MemoryStream();
    diagram.Save(stream, SaveFileFormat.XPS);
    stream.Position = 0;

    // Send a Diagram document to a printer using the XpsPrint API
    Print(stream, printerName, jobName, isWait);
}
Copy the code

Print Visio charts programmatically to the default printer in C#

You can use C# to programmatically print Visio chart files, such as VSDX, DWG, VST, etc. Please follow the following steps:

  • Create an instance of the Diagram class to load the Diagram to print.
  • Call the Print method with no arguments or arguments.

The following code explains how to programmatically print a Microsoft Diagram file to the default printer using C# :

// Load source Visio VSD or VSDX diagram
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

// Call the print method to print whole Diagram using the default printer
diagram.Print();
Copy the code

Print Visio diagrams programmatically to a specific printer using C#

You can print a Visio chart containing different shapes to a specific printer using the following steps:

  • Use the Diagram class to load the input Diagram file
  • Specify the printer name and job name and call the Print() method.

The following code details how to print the Diagram file to a specific printer in C# :

// Load source Visio diagram
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

// Call the print method to print whole Diagram using the printer name and set document name in the print job
diagram.Print("LaserJet1100", "Test Job");
Copy the code

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.