ArcObjects Library Reference  

PrintActiveViewArcPressVB_Net_Addin

About the Print active view with ArcPress Sample

[C#]

PrintActiveViewArcPressVB_Net_Addin.cs


[Visual Basic .NET]

PrintActiveViewArcPressVB_Net_Addin.vb

Imports System.Runtime.InteropServices
Imports System.Drawing
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Output
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.OutputExtensions
Imports ESRI.ArcGIS.esriSystem
Imports System.Windows.Forms

Public Class PrintActiveViewArcPressVB_Net_Addin
    Inherits ESRI.ArcGIS.Desktop.AddIns.Button

    Public Sub New()

    End Sub

    Protected Overrides Sub OnClick()
        'calls the PrintActiveViewVBParameterized function with an argument.
        PrintActiveViewVBParameterized(3)
    End Sub

    Protected Overrides Sub OnUpdate()
        Enabled = My.ArcMap.Application IsNot Nothing
    End Sub

    Private Sub PrintActiveViewVBParameterized(ByVal iResampleRatio As Integer)
        'Prints the active view of the document to the default printer using the 
        'ArcPress Printer Engine.  If the printer is not supported by the ArcPress
        'printer engine's "auto-select" driver selection method, the function exits and
        'no print is made.
        Dim docActiveView As IActiveView = My.ArcMap.Document.ActiveView
        Dim docPrinter As IPrinter
        Dim PrintAndExport As IPrintAndExport = New PrintAndExport
        Dim docArcPressPrinter As IArcPressPrinter
        Dim sNameRoot As String
        Dim iNumPages As Short

        docArcPressPrinter = New ArcPressPrinter()
        docPrinter = New ArcPressPrinter()

        'Attempt to auto-select a driver based on the printer's name.  If no driver can be 
        'auto-selected, exit the function and show a message about the failure.
        docArcPressPrinter.AutoSelectDriverByName(My.ArcMap.ThisApplication.Paper.PrinterName)
        If docArcPressPrinter.SelectedDriverId Is Nothing Then
            MessageBox.Show("Cannot auto-select ArcPress Driver for " & My.ArcMap.ThisApplication.Paper.PrinterName & ".", "ArcPress Driver Auto-select Error")
            Exit Sub
        End If

        'Pass the newly created ArcPressPrinter to docPrinter.
        docPrinter = docArcPressPrinter
        sNameRoot = "PrintActiveViewArcPressSample"

        'using the current printer.
        docPrinter.Paper = My.ArcMap.ThisApplication.Paper

        'make sure the paper orientation is set to the orientation matching the current view.
        docPrinter.Paper.Orientation = My.ArcMap.Document.PageLayout.Page.Orientation

        'set the spool filename (this is the job name that shows up in the print queue)
        docPrinter.SpoolFileName = sNameRoot

        ' Find out how many printer pages the output will cover.  iNumPages will always be 1 
        ' unless the user explicitly sets the tiling options in the file->Print dialog.  
        If TypeOf My.ArcMap.Document.ActiveView Is IPageLayout Then
            My.ArcMap.Document.PageLayout.Page.PrinterPageCount(docPrinter, 0, iNumPages)
        Else
            'always set the number of pages to 1 for a data view.
            iNumPages = 1
        End If

        Dim lCurrentPageNum As Short
        For lCurrentPageNum = 1 To iNumPages Step lCurrentPageNum + 1
            Try
                PrintAndExport.Print(docActiveView, docPrinter, My.ArcMap.Document.PageLayout.Page, lCurrentPageNum, iResampleRatio, Nothing)
            Catch ex As Exception
                MessageBox.Show("Printing cancelled for page " + lCurrentPageNum)
            End Try

        Next

    End Sub

End Class