Selecting Printer Tray Before Html Printing Programmatically

parshant.chugh

New member
Joined
Oct 1, 2008
Messages
1
Programming Experience
1-3
we need to change the printer tray programmatically through VB.net code. Can any body paste the sample code to change the default printer tray.

The issue description is :
In our application we print two pages simultaneously. one for cheque and one for invoice (both are in HTML format). But the requirement is to print both from different trays of printer. so we needs to change the printer tray so that cheque is printed from tray 1 and invoice is printed from tray 2.

Please suggest how to handle this dynamically.

The code to set default printer is :

VB.NET:
Private Function SetDefaultPrinter(ByVal Printername As String) ' Set the default printer 
    Dim DefaultPrinter As String
    Dim regKey As RegistryKey
    Dim Sys_var As String
    Dim index As Integer
    Try
        regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion\Windows", True)
        Sys_var = regKey.GetValue("Device")
        DefaultPrinter = Sys_var
        index = Sys_var.IndexOf(",")
        Sys_var = Sys_var.Remove(0, index)
        Sys_var = Printername & Sys_var
        regKey.SetValue("Device", Sys_var)
        'Sys_var = regKey.GetValue("Device")
        'regKey.Close()
        PrinterCheckflag = True ' Success in setting default printer 
    Catch ex As Exception
        regKey.SetValue("Device", DefaultPrinter)
        PrinterCheckflag = False ' Error in Setting Default printer 
        GlobalErrorMsg = Printername & " : Failed to set as default Printer."
        LogErrors(ex.ToString)
    Finally
        regKey.Close()
        Sys_var = String.Empty
        index = Nothing
    End Try
End Function

Other than printer now we need to set TRAY also through code. can any body help...
 
VB.NET:
Private Const DC_BINS = 6
Private Const DC_BINNAMES = 12
	

<DllImport("winspool.drv", SetLastError=true)> _
Public Shared Function DeviceCapabiities(byval device as string, byval port as string, byval capability as int16, byref outputBuffer as intptr, byval deviceMode as intptr) as Int32

To try and help you make a start i've included the function call you need. However this is tricky stuff. I'm having a go right now.
 
Daft suggestion time :D

We had this issue some time ago when we were using VB6 to print to network printers, and we found a clever workaround.

Install the same printer on your PC multiple times, but set the paper tray differently for each printer. For example, HP9000 Cheque Printer and HP9000 Invoice Printer. You would then print your cheque to HP9000 Cheque Printer etc etc.
 
Back
Top