ESC/POS Command

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ceming

    ESC/POS Command

    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
  • J French

    #2
    Re: ESC/POS Command

    On 28 Jul 2003 21:41:50 -0700, ceming@hotmail. com (Ceming) wrote:
    [color=blue]
    >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[/color]

    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.d rv" _
    Alias "OpenPrinte rA" (ByVal pPrinterName As String, _
    phPrinter As Long, _
    ByVal pDefault As Long) ' Third param
    changed to long
    Private Declare Function StartDocPrinter & Lib "winspool.d rv" _
    Alias "StartDocPrinte rA" (ByVal hPrinter As Long, _
    ByVal Level As Long, _
    pDocInfo As DOC_INFO_1)
    Private Declare Function StartPagePrinte r& Lib "winspool.d rv" _
    (ByVal hPrinter As Long)
    Private Declare Function WritePrinter& Lib "winspool.d rv" _
    (ByVal hPrinter As Long, _
    pBuf As Any, _
    ByVal cdBuf As Long, _
    pcWritten As Long)
    Private Declare Function EndDocPrinter& Lib "winspool.d rv" _
    (ByVal hPrinter As Long)
    Private Declare Function EndPagePrinter& Lib "winspool.d rv" _
    (ByVal hPrinter As Long)
    Private Declare Function ClosePrinter& Lib "winspool.d rv" _
    (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(Pri nter.DeviceName $, hPrinter, 0) = 0 Then
    Er = True
    Exit Function
    End If
    docinfo.pDocNam e = JobName$
    docinfo.pOutput File = vbNullString
    docinfo.pDataty pe = vbNullString
    JobId = StartDocPrinter (hPrinter, 1, docinfo)
    End Function

    Public Sub StartPage()
    Call StartPagePrinte r(hPrinter)
    End Sub

    Public Sub PrintData(S$)
    Dim written&
    Call WritePrinter(hP rinter, ByVal S$, Len(S$), written)
    End Sub

    Public Sub EndPage()
    Call EndPagePrinter( hPrinter)
    End Sub

    Public Sub CloseJob()
    Call EndDocPrinter(h Printer)
    Call ClosePrinter(hP rinter) ' Close when done
    End Sub



    Comment

    Working...