How to print receipts with ESC instructions
This article mainly introduces how to achieve ESC instructions to print tickets, the article is very detailed, has a certain reference value, interested friends must read it!
Take a look at the effect picture first.
Realize the print receipt format of a takeout store.
The code is as follows:
Char [] QRCODEchars1 = new char [] {(char) 29, (char) 40, (char) 107, (char) 15, (char) 0, (char) 49, (char) 80, (char) 48}; / / barcode
String QRCODEstr1 = new string (QRCODEchars1)
Char [] QRCODEchars2 = new char [] {(char) 29, (char) 40, (char) 107, (char) 15, (char) 0, (char) 49, (char) 81, (char) 48}
String QRCODEstr2 = new string (QRCODEchars2)
String Center = new string (new char [] {(char) 27, (char) 97, (char) 49}); / / centered
String Left = new string (new char [] {(char) 27, (char) 97, (char) 48}); / / left
String Size1 = new string (new char [] {(char) 29, (char) 33, (char) 0}); / / small font
String Size2 = new string (new char [] {(char) 29, (char) 33, (char) 17}); / / maximum font
String EnabledUnderline2 = new string (new char [] {(char) 27, (char) 45, (char) 2})
String DisabledUnderline = new string (new char [] {(char) 27, (char) 45, (char) 0})
String print2 = ""
Print2 + = Left + System.Environment.NewLine
Print2 + = Size2 + System.Environment.NewLine
Print2 + = "1 merchant ticket" + System.Environment.NewLine
Print2 + = "_ _" + System.Environment.NewLine
Print2 + = Center + System.Environment.NewLine
Print2 + = "* 1 Xiaoshun takeout *" + System.Environment.NewLine
Print2 + = Size1 + System.Environment.NewLine
Print2 + = "XXXX cafeteria" + System.Environment.NewLine
Print2 + = Left + System.Environment.NewLine
Print2 + = "time to place order: 9:41:36 on 2020-5-25" + System.Environment.NewLine
Print2 + = "* *" + System.Environment.NewLine
Print2 + = Size2 + System.Environment.NewLine
Print2 + = "Mixed Vegetables X 112.00" + System.Environment.NewLine
Print2 + = Size1 + System.Environment.NewLine
Print2 + = "_ other _" + System.Environment.NewLine
Print2 + = "packing fee: 0.00" + System.Environment.NewLine
Print2 + = "Commodity cost: 12.00" + System.Environment.NewLine
Print2 + = "delivery fee: 0.00" + System.Environment.NewLine
Print2 + = "reduction for the elderly: 12.00" + System.Environment.NewLine
Print2 + = "Total: 12.00 yuan" + System.Environment.NewLine
Print2 + = "_" + System.Environment.NewLine
Print2 + = Left + System.Environment.NewLine
Print2 + = Size2 + System.Environment.NewLine
Print2 + = "Mr. Zhang" + System.Environment.NewLine
Print2 + = "customer number: mobile phone number 5716" + System.Environment.NewLine
Print2 + = Size1 + System.Environment.NewLine
Print2 + = "Virtual number: 1234567891 ext. 568" + System.Environment.NewLine
Print2 + = "customer address: XX City, XX District, XXXXX Center" + System.Environment.NewLine
Print2 + = "[if you can't dial.]" + System.Environment.NewLine
Print2 + = "_ Please scan QR code _" + System.Environment.NewLine
Print2 + = Center + System.Environment.NewLine
Print2 + = QRCODEstr1 + "6S_1236S_123" + QRCODEstr2 + System.Environment.NewLine
Print2 + = "Thank You For Your Support!" + System.Environment.NewLine
Font size adjustment
We can write a simple code block to run to see the effect:
For (int I = 0; I