Get Available Paper Sizes for Installed Printers

L

lcifers

I'm writing a batch printing app that will interface with other
applications to print their native documents. All of the documents will
be printed on the same size paper.

On the main form, where the files are selected, are two comboboxes, one
for the user to select the printer, the other for the user to select
the paper size. Does anyone know how I can get the paper size for a
given printer? I can get a list of paper sizes using this code:

Dim objPrint As New System.Drawing.Printing.PrinterSettings
Dim strPrinters As String
Dim printerformat As System.Drawing.Printing.PaperSize

For Each printer As String In objPrint.InstalledPrinters

Dim PrinterObj As New
System.Drawing.Printing.PrinterSettings
PrinterObj.PrinterName = printer
For Each printerformat In PrinterObj.PaperSizes()

Try

Me.cboPaperSizes.Items.Add(printerformat.PaperName)
Catch ex As Exception

End Try

Next
Next


but it returns some paper sizes that I can't even use for that printer
(for exmaple 11X17 when the printer only prints 8.5X11 max). Does
anyone know how I can get ONLY paper sizes that the printer can print?

Thanks.

- Luther
 
L

lcifers

OK folks. Sorry for the mistake. These calls work fine. The problem is
that I wasn't testing each printer against the printer name so I was
getting paper sizes for every printer installed on my machine instead
of the one that was selected. The code should look like:

Private Sub cboPrinters_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cboPrinters.SelectedIndexChanged

Me.Cursor = Cursors.WaitCursor

If Not sender.text = "" Then
Me.cboPaperSizes.Visible = True
Me.cboPaperSizes.Items.Clear()

Dim objPrint As New System.Drawing.Printing.PrinterSettings
Dim strPrinters As String
Dim printerformat As System.Drawing.Printing.PaperSize

For Each printer As String In objPrint.InstalledPrinters

If printer = sender.text Then

Dim PrinterObj As New
System.Drawing.Printing.PrinterSettings
PrinterObj.PrinterName = printer
For Each printerformat In PrinterObj.PaperSizes()

Try


Me.cboPaperSizes.Items.Add(printerformat.PaperName)

Catch ex As Exception

End Try

Next
End If
Next

End If

Me.Cursor = Cursors.Default

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top