Este es el resultado de mi propia investigación del método IOutput, El IOutput le da una mayor posibilidad de controlar cómo se hace la impresión. Por ejemplo si quieres imprimir varias páginas .
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Customization of this sample
'http://resources.esri.com/help/9.3/ArcGISEngine/dotnet/025b5da7-9b10-4623-a51e-c038c348ce29.htm
<DllImport("GDI32.dll")> _
Public Shared Function GetDeviceCaps(ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
End Function
<DllImport("GDI32.dll")> _
Public Shared Function CreateDC(ByVal strDriver As String, ByVal strDevice As String, ByVal strOutput As String, ByVal pData As IntPtr) As Integer
End Function
<DllImport("User32.dll")> _
Public Shared Function ReleaseDC(ByVal hWnd As Integer, ByVal hDC As Integer) As Integer
End Function
Public Sub PrintActiveViewParameterized(ByVal iResampleRatio As Long)
' Prints the Active View of the document to selected output format.
'
Dim docActiveView As IActiveView = m_hookHelper.ActiveView
Dim docPrinter As IPrinter
Dim iPrevOutputImageQuality As Long
Dim docOutputRasterSettings As IOutputRasterSettings
Dim deviceRECT As ESRI.ArcGIS.esriSystem.tagRECT
Dim docPaper As IPaper
' printdocument is from the .NET assembly system.drawing.printing
Dim sysPrintDocumentDocument As System.Drawing.Printing.PrintDocument
Dim iNumPages As Short
Dim docPrinterBounds As IEnvelope
Dim VisibleBounds As IEnvelope
docPrinterBounds = New EnvelopeClass()
VisibleBounds = New EnvelopeClass()
' save the previous output image quality, so that when the export is complete it will be set back.
docOutputRasterSettings = TryCast(docActiveView.ScreenDisplay.DisplayTransformation, IOutputRasterSettings)
iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio
SetOutputQuality(docActiveView, iResampleRatio)
' Now we need to get the default printer name. Since this is a generic command,
' * we can't use the printername property of the document. So instead, we use the
' * System.Drawing.Printing objects to find the default printer.
'
docPrinter = New EmfPrinterClass()
'Fyller i defaultvärden i printerdialog
Dim PrintDialog1 As PrintDialog = New PrintDialog()
'Visar utskriftsdialog
Dim res As System.Windows.Forms.DialogResult = PrintDialog1.ShowDialog()
If res = DialogResult.Cancel Then
Return
End If
sysPrintDocumentDocument = New System.Drawing.Printing.PrintDocument()
docPaper = New PaperClass()
docPaper.Attach(PrintDialog1.PrinterSettings.GetHdevmode().ToInt32(), PrintDialog1.PrinterSettings.GetHdevnames().ToInt32())
'make sure the paper orientation is set to the orientation matching the current view.
docPaper.Orientation = m_hookHelper.PageLayout.Page.Orientation
' Now assign docPrinter the paper and with it the printername. This process is two steps
' * because you cannot change an IPrinter's printer except by passing it as a part of
' * the IPaper. That's why we setup docPrinter.Paper.PrinterName first.
'
docPrinter.Paper = docPaper
'set the spoolfilename (this is the job name that shows up in the print queue)
docPrinter.SpoolFileName = "PrintActiveViewSample"
' Get the printer's hDC, so we can use the Win32 GetDeviceCaps fuction to
' get Printer's Physical Printable Area x and y margins
Dim hInfoDC As Integer
hInfoDC = CreateDC(docPrinter.DriverName, docPrinter.Paper.PrinterName, "", IntPtr.Zero)
' Find out how many printer pages the output will cover.
If TypeOf m_hookHelper.ActiveView Is IPageLayout Then
m_hookHelper.PageLayout.Page.PrinterPageCount(docPrinter, 0, iNumPages)
Else
iNumPages = 1
End If
For lCurrentPageNum As Short = 0 To iNumPages - CType(1, Short)
m_hookHelper.PageLayout.Page.GetDeviceBounds(docPrinter, lCurrentPageNum, 0, docPrinter.Resolution, docPrinterBounds)
'Transfer PrinterBounds envelope, offsetting by PHYSICALOFFSETX
' the Win32 constant for PHYSICALOFFSETX is 112
' the Win32 constant for PHYSICALOFFSETY is 113
deviceRECT.bottom = CInt((docPrinterBounds.YMax - GetDeviceCaps(hInfoDC, 113)))
deviceRECT.left = CInt((docPrinterBounds.XMin - GetDeviceCaps(hInfoDC, 112)))
deviceRECT.right = CInt((docPrinterBounds.XMax - GetDeviceCaps(hInfoDC, 112)))
deviceRECT.top = CInt((docPrinterBounds.YMin - GetDeviceCaps(hInfoDC, 113)))
' Transfer offsetted PrinterBounds envelope back to the deviceRECT
docPrinterBounds.PutCoords(0, 0, deviceRECT.right - deviceRECT.left, deviceRECT.bottom - deviceRECT.top)
If TypeOf m_hookHelper.ActiveView Is IPageLayout Then
'get the visible bounds for this layout, based on the current page number.
m_hookHelper.PageLayout.Page.GetPageBounds(docPrinter, lCurrentPageNum, 0, VisibleBounds)
Else
'if it's not a page layout, export whatever's on screen at the printer's dpi.
'get the page
Dim pPage As IPage
pPage = m_hookHelper.PageLayout.Page
'get paper object
docPaper = docPrinter.Paper
If docPaper Is Nothing Then
MessageBox.Show("no paper defined")
Exit Sub
End If
'create an envelope for the bounds of the printer's page size in device units.
Dim pDeviceFrame As IEnvelope
pDeviceFrame = New EnvelopeClass()
pPage.GetDeviceBounds(docPrinter, 1, 0, docPrinter.Resolution, pDeviceFrame)
'create and populate an envelope with the bounds of the printer page.
Dim wksdevice As WKSEnvelope
pDeviceFrame.QueryWKSCoords(wksdevice)
'transfer the envelope to the deviceRECT.
deviceRECT.left = CInt(Math.Round(wksdevice.XMin))
deviceRECT.top = CInt(Math.Round(wksdevice.YMin))
deviceRECT.right = CInt(Math.Round(wksdevice.XMax))
deviceRECT.bottom = CInt(Math.Round(wksdevice.YMax))
'since this is a data view, not a pagelayout, we don't need VisibleBounds, so set it to NULL.
VisibleBounds = Nothing
End If
'Here's where the printing actually begins:
'==========================================
'The docPrinter.StartPrinting method returns the hDC of the printer, which we then
'use as the hDC parameter of activeview.output. ActiveView.Output is the function that
'draws the content on the active view, at the specified resolution, to the deviceRECT specified.
'VisibleBounds can be null, which means "print the active view", or can be set to a zoom extent.
If iNumPages = 1 Then
VisibleBounds = Nothing
End If
m_hookHelper.ActiveView.Output(docPrinter.StartPrinting(docPrinterBounds, 0), docPrinter.Resolution, deviceRECT, VisibleBounds, Nothing)
'here we call FinishPrinting, which actually flushes the output to the printer.
docPrinter.FinishPrinting()
'now set the output quality back to the previous output quality.
SetOutputQuality(docActiveView, iPrevOutputImageQuality)
Next
'release the DC...
ReleaseDC(0, hInfoDC)
End Sub
Private Sub SetOutputQuality(ByVal docActiveView As IActiveView, ByVal iResampleRatio As Long)
' This function sets OutputImageQuality for the active view. If the active view is a pagelayout, then
' * it must also set the output image quality for EACH of the Maps in the pagelayout.
'
Dim docGraphicsContainer As IGraphicsContainer
Dim docElement As IElement
Dim docOutputRasterSettings As IOutputRasterSettings
Dim docMapFrame As IMapFrame
Dim tmpActiveView As IActiveView
If TypeOf docActiveView Is IMap Then
docOutputRasterSettings = TryCast(docActiveView.ScreenDisplay.DisplayTransformation, IOutputRasterSettings)
docOutputRasterSettings.ResampleRatio = CInt(iResampleRatio)
ElseIf TypeOf docActiveView Is IPageLayout Then
'assign ResampleRatio for PageLayout
docOutputRasterSettings = TryCast(docActiveView.ScreenDisplay.DisplayTransformation, IOutputRasterSettings)
docOutputRasterSettings.ResampleRatio = CInt(iResampleRatio)
'and assign ResampleRatio to the Maps in the PageLayout
docGraphicsContainer = TryCast(docActiveView, IGraphicsContainer)
docGraphicsContainer.Reset()
docElement = docGraphicsContainer.[Next]()
While docElement IsNot Nothing
If TypeOf docElement Is IMapFrame Then
docMapFrame = TryCast(docElement, IMapFrame)
tmpActiveView = TryCast(docMapFrame.Map, IActiveView)
docOutputRasterSettings = TryCast(tmpActiveView.ScreenDisplay.DisplayTransformation, IOutputRasterSettings)
docOutputRasterSettings.ResampleRatio = CInt(iResampleRatio)
End If
docElement = docGraphicsContainer.[Next]()
End While
docMapFrame = Nothing
docGraphicsContainer = Nothing
tmpActiveView = Nothing
End If
docOutputRasterSettings = Nothing
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''