Get Available Paper Sizes for Installed Printers

L

lcifers

I posted this in a VB.NET group, but no response. Hoping for some help
here. I'm writing this app in VB.NET

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.Printe­rSettings
Dim strPrinters As String
Dim printerformat As System.Drawing.Printing.PaperS­ize


For Each printer As String In objPrint.InstalledPrinters


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


Try


Me.cboPaperSizes.Items.Add(pri­nterformat.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

Private Sub cboPrinters_SelectedIndexChang­ed(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cboPrinters.SelectedIndexChang­ed


Me.Cursor = Cursors.WaitCursor


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


Dim objPrint As New
System.Drawing.Printing.Printe­rSettings
Dim strPrinters As String
Dim printerformat As System.Drawing.Printing.PaperS­ize


For Each printer As String In objPrint.InstalledPrinters


If printer = sender.text Then


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


Try


Me.cboPaperSizes.Items.Add(pri­nterformat.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