Greetings,
I have code which prints a document who's attributes are saved as
flags in a database. One of the those attributes is letter or legal.
When I am printing, I use the following code, which is the ONLY way I
could come up with to reliably print to legal paper, assuming a
default of letter. There HAS to be a better way. I'm having to
loop through all paper options on the remote server's printer, until I
find the one that corresponds to legal or letter. The problem is that
this looping on a remote (networked) server is very SLOW!!!! I need
like a one line solution that doesn't require me to loop through
remote server's printer settings.
Any thoughts about how I could optimize the selection of the legal
papersize?
p = New PrintDocument
''call print page event handler
AddHandler p.PrintPage, AddressOf pd_printpage
''name the printing service (que)
p.DocumentName = "GIB Non-System Document " & strItem
With p.DefaultPageSettings.Margins
.Top = 40
.Bottom = 40
.Left = 40
.Right = 40
End With
''which printer
p.PrinterSettings.PrinterName = "\\civility\" &
strPrinterName
'paper size
Select Case strSize
Case "1"
'legal
For i = 0 To p.PrinterSettings.PaperSizes.Count -
1
pkSize = p.PrinterSettings.PaperSizes.Item(i)
If pkSize.Kind = PaperKind.Legal Then
p.DefaultPageSettings.PaperSize =
p.PrinterSettings.PaperSizes.Item(i)
End If
Next
Case "0"
'letter
For i = 0 To p.PrinterSettings.PaperSizes.Count -
1
pkSize = p.PrinterSettings.PaperSizes.Item(i)
If pkSize.Kind = PaperKind.Letter Then
p.DefaultPageSettings.PaperSize =
p.PrinterSettings.PaperSizes.Item(i)
End If
Next
End Select
Try
p.Print() ' - raises printpage event
David Fields