By Edhy Rijo - 10/14/2009
Hi guys,
I have the need to generate 40 columns receipts using standard Receipt Printers like the Star SP200 or the Epson series. Have you guys used Report SharpShooter (RSS) with these kind of printer? if so how would you control the receipt's length so when the receipt finish printing it will only eject a couple of line to cut the paper?
In my case, I use the "Generic Text" print driver since I don't have any special needs for using a custom driver yet.
Thanks!
|
By Paul Chase - 10/16/2009
Edhy I use DevExpress as my reporting tool so can't comment on SharpShooter. However I did run into issues several trying to use a report writer for this type of thing. I ended up talking directly to the printer via API calls and at least in my case it was easier and gives me the level of control I needed.
|
By Edhy Rijo - 10/16/2009
Thanks Paul,
I have to work on this today, so I will explore the API method.
|
By Paul Chase - 10/16/2009
Edhy here is a class wrapping API printer calls that I am using. I see if i can pull an example using it from my code in a few.Public Class PrintAPI#Region "OpenPrinter"<DllImport( "winspool.drv", EntryPoint:="OpenPrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _<OutAttribute()> ByRef phPrinter As Int32, _<InAttribute(), MarshalAs(UnmanagedType.LPStruct)> ByVal pDefault As PRINTER_DEFAULTS _) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="OpenPrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _<OutAttribute()> ByRef phPrinter As Int32, _<InAttribute()> ByVal pDefault As Int32 _) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="OpenPrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _<OutAttribute()> ByRef phPrinter As IntPtr, _<InAttribute()> ByVal pDefault As PRINTER_DEFAULTS _) As BooleanEnd Function#End Region#Region "ClosePrinter"<DllImport( "winspool.drv", EntryPoint:="ClosePrinter", _SetLastError:= True, _ExactSpelling:= True, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function ClosePrinter(<InAttribute()> ByVal hPrinter As IntPtr) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="ClosePrinter", _SetLastError:= True, _ExactSpelling:= True, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function ClosePrinter(<InAttribute()> ByVal hPrinter As Integer) As BooleanEnd Function#End Region#Region "GetPrinter"<DllImport( "winspool.drv", EntryPoint:="GetPrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function GetPrinter _(<InAttribute()> ByVal hPrinter As IntPtr, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal lpPrinter As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef lpbSizeNeeded As Int32) As BooleanEnd Function#End Region#Region "EnumPrinters"<DllImport( "winspool.drv", EntryPoint:="EnumPrinters", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EnumPrinters(<InAttribute()> ByVal Flags As ConstantEnumerations.EnumPrinterFlags, _<InAttribute()> ByVal Name As String, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal lpBuf As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32, _<OutAttribute()> ByRef pcbReturned As Int32) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="EnumPrinters", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EnumPrinters(<InAttribute()> ByVal Flags As ConstantEnumerations.EnumPrinterFlags, _<InAttribute()> ByVal Name As IntPtr, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal lpBuf As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32, _<OutAttribute()> ByRef pcbReturned As Int32) As BooleanEnd Function#End Region#Region "GetPrinterDriver"<DllImport( "winspool.drv", EntryPoint:="GetPrinterDriver", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function GetPrinterDriver _(<InAttribute()> ByVal hPrinter As IntPtr, _<InAttribute()> ByVal pEnvironment As String, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal lpDriverInfo As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef lpbSizeNeeded As Int32) As BooleanEnd Function#End Region#Region "EnumPrinterDrivers"<DllImport( "winspool.drv", EntryPoint:="EnumPrinterDrivers", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EnumPrinterDrivers(<InAttribute()> ByVal ServerName As String, _<InAttribute()> ByVal Environment As String, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal lpBuf As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32, _<OutAttribute()> ByRef pcbReturned As Int32) As BooleanEnd Function#End Region#Region "SetPrinter"<DllImport( "winspool.drv", EntryPoint:="SetPrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function SetPrinter _(<InAttribute()> ByVal hPrinter As IntPtr, _<InAttribute()> ByVal Level As Int32, _<InAttribute()> ByVal pPrinter As IntPtr, _<InAttribute()> ByVal Command As ConstantEnumerations.PrinterControlCommands) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="SetPrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function SetPrinter _(<InAttribute()> ByVal hPrinter As IntPtr, _<InAttribute(), MarshalAs(UnmanagedType.U4)> ByVal Level As ConstantEnumerations.PrinterInfoLevels, _<InAttribute(), MarshalAs(UnmanagedType.LPStruct)> ByVal pPrinter As PRINTER_INFO_2, _<InAttribute(), MarshalAs(UnmanagedType.U4)> ByVal Command As PrinterControlCommands) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="SetPrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function SetPrinter _(<InAttribute()> ByVal hPrinter As IntPtr, _<InAttribute(), MarshalAs(UnmanagedType.U4)> ByVal Level As PrinterInfoLevels, _<InAttribute(), MarshalAs(UnmanagedType.LPStruct)> ByVal pPrinter As PRINTER_INFO_3, _<InAttribute(), MarshalAs(UnmanagedType.U4)> ByVal Command As PrinterControlCommands) As BooleanEnd Function#End Region#Region "GetJob"<DllImport( "winspool.drv", EntryPoint:="GetJob", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function GetJob _(<InAttribute()> ByVal hPrinter As IntPtr, _<InAttribute()> ByVal dwJobId As Int32, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal lpJob As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef lpbSizeNeeded As Int32) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="GetJob", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function GetJob _(<InAttribute()> ByVal hPrinter As Int32, _<InAttribute()> ByVal dwJobId As Int32, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal lpJob As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef lpbSizeNeeded As Int32) As BooleanEnd Function#End Region#Region "FindFirstPrinterChangeNotification"#End Region#Region "FreePrinterNotifyInfo"<DllImport( "winspool.drv", EntryPoint:="FreePrinterNotifyInfo", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function FreePrinterNotifyInfo _(<InAttribute()> ByVal lppPrinterNotifyInfo As IntPtr) As BooleanEnd Function#End Region#Region "FindClosePrinterChangeNotification"<DllImport( "winspool.drv", EntryPoint:="FindClosePrinterChangeNotification", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function FindClosePrinterChangeNotification _(<InAttribute()> ByVal hChangeObject As IntPtr) As BooleanEnd Function#End Region#Region "EnumJobs"<DllImport( "winspool.drv", EntryPoint:="EnumJobs", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EnumJobs _(<InAttribute()> ByVal hPrinter As IntPtr, _<InAttribute()> ByVal FirstJob As Int32, _<InAttribute()> ByVal NumberOfJobs As Int32, _<InAttribute(), MarshalAs(UnmanagedType.U4)> ByVal Level As JobInfoLevels, _<OutAttribute()> ByVal pbOut As IntPtr, _<InAttribute()> ByVal cbIn As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32, _<OutAttribute()> ByRef pcReturned As Int32 _) As BooleanEnd Function#End Region#Region "SetJob"<DllImport( "winspool.drv", EntryPoint:="SetJob", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function SetJob _(<InAttribute()> ByVal hPrinter As IntPtr, _<InAttribute()> ByVal dwJobId As Int32, _<InAttribute()> ByVal Level As Int32, _<InAttribute()> ByVal lpJob As IntPtr, _<InAttribute(), MarshalAs(UnmanagedType.U4)> ByVal dwCommand As PrintJobControlCommands _) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="SetJob", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function SetJob _( ByVal hPrinter As IntPtr, _ByVal dwJobId As Int32, _ByVal Level As Int32, _<MarshalAs(UnmanagedType.LPStruct)> ByVal lpJob As JOB_INFO_1, _ByVal dwCommand As PrintJobControlCommands _) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="SetJob", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function SetJob _( ByVal hPrinter As IntPtr, _ByVal dwJobId As Int32, _ByVal Level As Int32, _<MarshalAs(UnmanagedType.LPStruct)> ByVal lpJob As JOB_INFO_2, _ByVal dwCommand As PrintJobControlCommands _) As BooleanEnd Function#End Region#Region "EnumMonitors"<DllImport( "winspool.drv", EntryPoint:="EnumMonitors", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EnumMonitors(<InAttribute()> ByVal ServerName As String, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal lpBuf As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32, _<OutAttribute()> ByRef pcReturned As Int32) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="EnumMonitors", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EnumMonitors(<InAttribute()> ByVal pServerName As IntPtr, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal lpBuf As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32, _<OutAttribute()> ByRef pcReturned As Int32) As BooleanEnd Function#End Region#Region "DocumentProperties"<DllImport( "winspool.drv", EntryPoint:="DocumentProperties", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function DocumentProperties _(<InAttribute()> ByVal hwnd As IntPtr, _<InAttribute()> ByVal hPrinter As IntPtr, _<InAttribute()> ByVal pPrinterName As String, _<OutAttribute()> ByRef pDevModeOut As IntPtr, _<InAttribute()> ByVal pDevModeIn As IntPtr, _<InAttribute()> ByVal Mode As DocumentPropertiesModes) As Int32End Function#End Region#Region "DeviceCapabilities"<DllImport( "winspool.drv", EntryPoint:="DeviceCapabilities", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function DeviceCapabilities(<InAttribute()> ByVal pPrinterName As String, _<InAttribute()> ByVal pPortName As String, _<InAttribute(), MarshalAs(UnmanagedType.U4)> ByVal CapbilityIndex As PrintDeviceCapabilitiesIndexes, _<OutAttribute()> ByRef lpOut As IntPtr, _<InAttribute()> ByVal pDevMode As IntPtr) As Int32End Function#End Region#Region "GetPrinterDriverDirectory"<DllImport( "winspool.drv", EntryPoint:="GetPrinterDriverDirectory", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function GetPrinterDriverDirectory( _<InAttribute()> ByVal ServerName As String, _<InAttribute()> ByVal Environment As String, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByRef DriverDirectory As String, _<InAttribute()> ByVal BufferSize As Int32, _<OutAttribute()> ByRef BytesNeeded As Int32) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="GetPrinterDriverDirectory", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function GetPrinterDriverDirectory( _<InAttribute()> ByVal ServerName As IntPtr, _<InAttribute()> ByVal Environment As IntPtr, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByRef DriverDirectory As String, _<InAttribute()> ByVal BufferSize As Int32, _<OutAttribute()> ByRef BytesNeeded As Int32) As BooleanEnd Function#End Region#Region "AddPrinterDriver"<DllImport( "winspool.drv", EntryPoint:="AddPrinterDriver", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function AddPrinterDriver( _<InAttribute()> ByVal ServerName As String, _<InAttribute()> ByVal Level As Int32, _<InAttribute(), MarshalAs(UnmanagedType.LPStruct)> ByVal pDriverInfo As DRIVER_INFO_2) As BooleanEnd Function#End Region#Region "EnumPorts"<DllImport( "winspool.drv", EntryPoint:="EnumPorts", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EnumPorts( _<InAttribute()> ByVal ServerName As String, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal pbOut As IntPtr, _<InAttribute()> ByVal cbIn As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32, _<OutAttribute()> ByRef pcReturned As Int32 _) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="EnumPorts", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EnumPorts( _<InAttribute()> ByVal ServerName As IntPtr, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal pbOut As IntPtr, _<InAttribute()> ByVal cbIn As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32, _<OutAttribute()> ByRef pcReturned As Int32 _) As BooleanEnd Function#End Region#Region "SetPort"<DllImport( "winspool.drv", EntryPoint:="SetPort", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function SetPort( _<InAttribute()> ByVal ServerName As String, _<InAttribute()> ByVal PortName As String, _<InAttribute()> ByVal Level As Long, _<InAttribute(), MarshalAs(UnmanagedType.LPStruct)> ByVal PortInfo As PORT_INFO_3) As BooleanEnd Function#End Region#Region "EnumPrintProcessors"<DllImport( "winspool.drv", EntryPoint:="EnumPrintProcessors", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EnumPrintProcessors(<InAttribute()> ByVal ServerName As String, _<InAttribute()> ByVal Environment As String, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal lpBuf As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32, _<OutAttribute()> ByRef pcbReturned As Int32) As BooleanEnd Function#End Region#Region "EnumPrintProcessorDataTypes"<DllImport( "winspool.drv", EntryPoint:="EnumPrintProcessorDatatypes", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EnumPrinterProcessorDataTypes(<InAttribute()> ByVal ServerName As String, _<InAttribute()> ByVal PrintProcessorName As String, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal pDataTypes As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32, _<OutAttribute()> ByRef pcReturned As Int32) As BooleanEnd Function#End Region#Region "GetForm"<DllImport( "winspool.drv", EntryPoint:="GetForm", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function GetForm(<InAttribute()> ByVal PrinterHandle As IntPtr, _<InAttribute()> ByVal FormName As String, _<InAttribute()> ByVal Level As Integer, _<OutAttribute()> ByRef pForm As FORM_INFO_1, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32 _) As BooleanEnd Function#End Region#Region "SetForm"<DllImport( "winspool.drv", EntryPoint:="SetForm", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function SetForm(<InAttribute()> ByVal PrinterHandle As IntPtr, _<InAttribute()> ByVal FormName As String, _<InAttribute()> ByVal Level As Integer, _<InAttribute()> ByRef pForm As FORM_INFO_1 _) As BooleanEnd Function#End Region#Region "EnumForms"<DllImport( "winspool.drv", EntryPoint:="EnumForms", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EnumForms( _<InAttribute()> ByVal hPrinter As IntPtr, _<InAttribute()> ByVal Level As Int32, _<OutAttribute()> ByVal pForm As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32, _<OutAttribute()> ByRef pcFormsReturned As Int32) As BooleanEnd Function#End Region#Region "ReadPrinter"<DllImport( "winspool.drv", EntryPoint:="ReadPrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function ReadPrinter(<InAttribute()> ByVal hPrinter As IntPtr, _<OutAttribute()> ByVal pBuffer As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="ReadPrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function ReadPrinter(<InAttribute()> ByVal hPrinter As Int32, _<OutAttribute()> ByVal pBuffer As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32) As BooleanEnd Function#End Region#Region "WritePrinter"<DllImport( "winspool.drv", EntryPoint:="WritePrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function WritePrinter(<InAttribute()> ByVal hPrinter As IntPtr, _<OutAttribute()> ByVal pBuffer As IntPtr, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32) As BooleanEnd Function<DllImport( "winspool.drv", EntryPoint:="WritePrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function WritePrinter(<InAttribute()> ByVal hPrinter As IntPtr, _<OutAttribute()> ByVal data As String, _<InAttribute()> ByVal cbBuf As Int32, _<OutAttribute()> ByRef pcbNeeded As Int32) As BooleanEnd Function#End Region#Region "StartDocPrinter"<DllImport( "winspool.drv", EntryPoint:="StartDocPrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function StartDocPrinter(<InAttribute()> ByVal hPrinter As Int32, _<InAttribute()> ByVal Level As Int32, _<InAttribute(), MarshalAs(UnmanagedType.LPStruct)> ByVal DocInfo As DOC_INFO) As BooleanEnd Function#End Region#Region "EndDocPrinter"<DllImport( "winspool.drv", EntryPoint:="EndDocPrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EndDocPrinter(<InAttribute()> ByVal hPrinter As Int32) As BooleanEnd Function#End Region#Region "StartPagePrinter"<DllImport( "winspool.drv", EntryPoint:="StartPagePrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function StartPagePrinter(<InAttribute()> ByVal hPrinter As Int32) As BooleanEnd Function#End Region#Region "EndPagePrinter"<DllImport( "winspool.drv", EntryPoint:="EndPagePrinter", _SetLastError:= True, CharSet:=CharSet.Ansi, _ExactSpelling:= False, _CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function EndPagePrinter(<InAttribute()> ByVal hPrinter As Int32) As BooleanEnd Function#End RegionEnd Class 'PrintAPI
|
By Edhy Rijo - 10/16/2009
Thanks a lot Paul.
|
By Paul Chase - 10/16/2009
Edhy here is a stripped down version of what I am using hope it helps.'--Local variablesDim hPrinter As New System.IntPtr() 'Printer HandleDim DocInfo As New Base.Printing.Strucs.DOC_INFODim lnWritten As Integer = 0Dim LoString As New StringBuilder'--Open PrinterIf ActionLabor.Payroll.Base.Printing.PrintAPI.OpenPrinter("receipt", hPrinter, 0) = False ThenReturn FalseEnd If'hPrinter contains the handle for the printer opened'If hPrinter is 0 then an error has occuredIf hPrinter = 0 ThenReturn FalseEnd IfTryDocInfo.DocumentName = "Rcpt# " & Me.RctNbrDocInfo.DataType = "RAW"PrintAPI.StartDocPrinter(hPrinter, 1, DocInfo) PrintAPI.StartPagePrinter(hPrinter) 'set output to printerLoString.AppendLine( String.Format("----{0}----", "Header"))LoString.AppendLine( "Line2")If Not PrintAPI.WritePrinter(hPrinter, LoString.ToString, LoString.Length, lnWritten) ThenReturn FalseEnd IfCatch e As Exception'ToDo:--Add Here Base.Common.ErrorHandling.LogError(e) ' Console.WriteLine(e.Message)Return FalseFinally'ClosePrintAPI.EndPagePrinter(hPrinter) PrintAPI.EndDocPrinter(hPrinter) PrintAPI.ClosePrinter(hPrinter) End TryReturn True
|
By Edhy Rijo - 10/16/2009
That's great Paul, thanks again, I will implement this now.
|
By Juan Carlos Pazos - 10/16/2009
Hi EdhyYou can take a look to this resources: http://social.msdn.microsoft.com/Forums/en-US/posfordotnet/ http://www.microsoft.com/windowsembedded/en-us/products/readyproducts/posready/default.mspx This a POS implementation for NET. Could be usefull, I found an aplications (AEVI POS) that use this libraries. Regards
|
By Edhy Rijo - 10/20/2009
Hola Juan Carlos,
I am sorry I skip this post. Thanks a lot for this information, I will review it and let you know if I can use it.
|
|