Send ESC commands to a printer in C#

后端 未结 3 1536
长情又很酷
长情又很酷 2020-12-03 16:16

My application needs to print invoices, then a get the invoice from database, insert information on the invoice in a big string (telling the line, column, etc.) after this I

3条回答
  •  执笔经年
    2020-12-03 16:39

    "....OpenPrinter(printerName.Normalize(), out printerHandle, IntPtr.Zero)..."

    might needed to set IntPtr.Zero to raw too.

    Printers, especially dot matrix, it can be direct using DOS, CMD method, which much simplest and faster for printing also can using basic ESC/0x1b command codes to controll the printer,. . etc.

    as windowos/graphic, it can be graphics and raw by setting openprinter(,,printer_defaults) printer_defaults and doc-inf, pls refer win32 sdk references.

    for any raw printing it can uses ESC command (refer to printer manual details) to print any graphic as what windows driver did.

    as printing raw, it just append any of the first 20 ascii, such as oxoc(formfeed) 0x0doa(0x0a, 0x0d, \n or newline) each printer has slight ESC commands differences but using the master ESC command is fined for most of Dot matrix similar.

    as raw mode example follows, FormFeed , \n & \r

    char cFormfeed=0x0c; // or \f

    char cStr[]="1=text,......@\n2=text.....\r\f3=text......."; //use \f not using cFormfeed you can work it out

    cStr > lpt1; //output to printer dos or cmd method, of cause must get the lpt1 available.

    print out will be

    first page

    1=text,......@

    2=text.....

    at 2nd page is

    3=text.......

    hope this can be help, good luck.

提交回复
热议问题