On 28 Jul 2003 21:41:50 -0700,
ce****@hotmail.com (Ceming) wrote:
I create VB program that must print to the dot matrix printer. I'm
using printer object, but cannot send ESC/POS Command that my printer
recognise to set the layout of the print out.
How can i send ESC/POS Command using printer object in VB?
Thanks
The best method I know of is to bypass the VB Printer Object and send
data directly into the Spooler
Here is a Class that will do just that :-
Option Explicit: DefObj A-Z
Private Type DOC_INFO_1
pDocName As String
pOutputFile As String
pDatatype As String
End Type
Private Declare Function OpenPrinter& Lib "winspool.drv" _
Alias "OpenPrinterA" (ByVal pPrinterName As String, _
phPrinter As Long, _
ByVal pDefault As Long) ' Third param
changed to long
Private Declare Function StartDocPrinter& Lib "winspool.drv" _
Alias "StartDocPrinterA" (ByVal hPrinter As Long, _
ByVal Level As Long, _
pDocInfo As DOC_INFO_1)
Private Declare Function StartPagePrinter& Lib "winspool.drv" _
(ByVal hPrinter As Long)
Private Declare Function WritePrinter& Lib "winspool.drv" _
(ByVal hPrinter As Long, _
pBuf As Any, _
ByVal cdBuf As Long, _
pcWritten As Long)
Private Declare Function EndDocPrinter& Lib "winspool.drv" _
(ByVal hPrinter As Long)
Private Declare Function EndPagePrinter& Lib "winspool.drv" _
(ByVal hPrinter As Long)
Private Declare Function ClosePrinter& Lib "winspool.drv" _
(ByVal hPrinter As Long)
Private hPrinter&, _
docinfo As DOC_INFO_1, _
PrinterName$
Public Function OpenJob(JobName$, Er As Boolean)
Dim JobId&
Er = False
If OpenPrinter(Printer.DeviceName$, hPrinter, 0) = 0 Then
Er = True
Exit Function
End If
docinfo.pDocName = JobName$
docinfo.pOutputFile = vbNullString
docinfo.pDatatype = vbNullString
JobId = StartDocPrinter(hPrinter, 1, docinfo)
End Function
Public Sub StartPage()
Call StartPagePrinter(hPrinter)
End Sub
Public Sub PrintData(S$)
Dim written&
Call WritePrinter(hPrinter, ByVal S$, Len(S$), written)
End Sub
Public Sub EndPage()
Call EndPagePrinter(hPrinter)
End Sub
Public Sub CloseJob()
Call EndDocPrinter(hPrinter)
Call ClosePrinter(hPrinter) ' Close when done
End Sub