Quantcast
Channel: Forums - ArcGIS for Desktop - General
Viewing all articles
Browse latest Browse all 2328

PrintDialog1 help

$
0
0
I have code that creates and displays a map layout.

My form has a print button that calls the procedure below. This opens the Print Dialog, but the dialogue doesn't have the correct page settings i.e. paper size and orientation. If I open the print dialogue manually it has the correct page settings already.

Please help I'm really struggling with this problem.


Regards

Chris




Private Sub printTemplate()
'____________________________________________________________

'Set the mouse cursor to the hour glass
Dim pMouseCursor As IMouseCursor
pMouseCursor = New MouseCursor
pMouseCursor.SetCursor(2)
'The hour glass should automatically clear when the procedure exits
'____________________________________________________________

Try
Dim pMxDoc As IMxDocument
pMxDoc = WBC_Tools_ArcGIS_Extension.m_pApp.Document

Dim pMxApp As IMxApplication
pMxApp = WBC_Tools_ArcGIS_Extension.m_pApp

Dim pPrinter As IPrinter
Dim pPageLayout As IPageLayout
pPrinter = pMxApp.Printer
pPrinter.Paper = pMxApp.Paper
pPageLayout = pMxDoc.PageLayout

Dim pActiveView As IActiveView
pActiveView = pMxDoc.ActiveView

Dim pEmfPrinter As IEmfPrinter
pEmfPrinter = pPrinter




Dim strSelPrinter As String = ""
strSelPrinter = cboPrinter.SelectedItem

'Dim strPaperSize As String = ""
'strPaperSize = cboPaper.Text

Dim sysPrintDocument As PrintDocument
sysPrintDocument = New PrintDocument()
sysPrintDocument.PrinterSettings.PrinterName = strSelPrinter


'Show print dialog
Dim PrintDialog1 As PrintDialog = New PrintDialog()
PrintDialog1.Document = sysPrintDocument

Dim res As System.Windows.Forms.DialogResult = PrintDialog1.ShowDialog()
If res = DialogResult.Cancel Then
Return
End If
Dim pPaper As IPaper
pPaper = pMxApp.Paper
pPaper.Attach(PrintDialog1.PrinterSettings.GetHdevmode().ToInt32(), PrintDialog1.PrinterSettings.GetHdevnames().ToInt32())

'assing docPrinter's paper. We have to do this in two steps because you cannot change a
'printers' paper after it's assigned. That's why we set docPaper.PrinterName first.
pPrinter.Paper = pPaper

'set the spoolfilename (this is the job name that shows up in the print queue)
pPrinter.SpoolFileName = "WBC Tools - Print Map Wizard"

Dim iNumPages As Short = PrintDialog1.PrinterSettings.Copies
Dim PrintAndExport As IPrintAndExport = New PrintAndExport
Try
PrintAndExport.Print(pActiveView, pEmfPrinter, pPageLayout.Page, iNumPages, 0, Nothing)
Catch ex As Exception
MessageBox.Show("An error has occurred: " + ex.Message)
End Try

pEmfPrinter = Nothing
pPrinter = Nothing

Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, WBC_Tools_ArcGIS_Extension.m_strTitle)
End Try
End Sub

Viewing all articles
Browse latest Browse all 2328

Trending Articles