Delen via


How to: Programmatically print Visio documents

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

You can print a complete Microsoft Office Visio document or only a specific page.

For details about the print methods, see the VBA reference documentation for the Microsoft.Office.Interop.Visio.Document.Print method and Microsoft.Office.Interop.Visio.Page.Print method.

To print a complete document

  • Call the Microsoft.Office.Interop.Visio.Document.Print method of the Microsoft.Office.Interop.Visio.Document object that you want to print.

    The following code example prints the active document. To use this example, run the code from the ThisAddIn class in your project.

    this.Application.ActiveDocument.Print();
    
    Me.Application.ActiveDocument.Print()
    

To print a page of a document

  • Call the Microsoft.Office.Interop.Visio.Pages.Print method of the Microsoft.Office.Interop.Visio.Pages object that you want to print.

    The following code example prints the first page of the active document. To use this example, run the code from the ThisAddIn class in your project.

    int pageIndex = 1;
    Visio.Pages visioDocPages = this.Application.ActiveDocument.Pages;
    if (pageIndex <= visioDocPages.Count)
        visioDocPages[pageIndex].Print();
    
    Dim pageIndex As Integer = 1
    Dim visioDocPages As Visio.Pages = Me.Application.ActiveDocument.Pages
    If pageIndex <= visioDocPages.Count Then
        visioDocPages(pageIndex).Print()
    End If
    

See also