StrataFrame Forum

Report SharpShooter and Receipt Printers....

http://forum.strataframe.net/Topic24918.aspx

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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End Function

<DllImport("winspool.drv", EntryPoint:="ClosePrinter", _

SetLastError:=True, _

ExactSpelling:=True, _

CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function ClosePrinter(<InAttribute()> ByVal hPrinter As Integer) As Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Int32

End 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 Int32

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End 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 Boolean

End Function

#End Region

End 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 variables

Dim hPrinter As New System.IntPtr() 'Printer Handle

Dim DocInfo As New Base.Printing.Strucs.DOC_INFO

Dim lnWritten As Integer = 0

Dim LoString As New StringBuilder

'--Open Printer

If ActionLabor.Payroll.Base.Printing.PrintAPI.OpenPrinter("receipt", hPrinter, 0) = False Then

Return False

End If

'hPrinter contains the handle for the printer opened

'If hPrinter is 0 then an error has occured

If hPrinter = 0 Then

Return False

End If

Try

DocInfo.DocumentName = "Rcpt# " & Me.RctNbr

DocInfo.DataType = "RAW"

PrintAPI.StartDocPrinter(hPrinter, 1, DocInfo)

PrintAPI.StartPagePrinter(hPrinter)

'set output to printer

LoString.AppendLine(String.Format("----{0}----", "Header"))

LoString.AppendLine("Line2")

If Not PrintAPI.WritePrinter(hPrinter, LoString.ToString, LoString.Length, lnWritten) Then

Return False

End If

Catch e As Exception

'ToDo:--Add Here

Base.Common.ErrorHandling.LogError(e)

' Console.WriteLine(e.Message)

Return False

Finally

'Close

PrintAPI.EndPagePrinter(hPrinter)

PrintAPI.EndDocPrinter(hPrinter)

PrintAPI.ClosePrinter(hPrinter)

End Try

Return 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 Edhy

You 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.