As I described in my previous posts, ESC/POS commands are Universal Commands used for printing on Thermal Printer. These commands are supported by almost all Thermal Printers in the market.
Please follow these ESC/POS commands which are used in my next successive posts how to print receipt, label, Image/Logo, Barcode, QR Code etc. Here I’ll use mmOutputStream instance which I have created in my previous post.
How to initialize Thermal printer-
Before or after printing of Image, Barcode, QR Code, and Receipts, you have to initialize the thermal printer. Otherwise some garbage characters may be printed.
public static final byte[] INIT = {0x1B, 0x40};
mmOutputStream.write(INIT);
How to select Font in Thermal printer–
public static byte[] SELECT_FONT_A = {27, 33, 0}; // 12 * 24 dots
public static byte[] SELECT_FONT_B = {27, 33, 1}; // 9 * 24 dots
mmOutputStream.write(SELECT_FONT_B);
How to auto feed Thermal paper to black bar mark after printing–
public static byte[] FEED_PAPER_TO_BLACK_BAR = {0x0C};
mmOutputStream.write(FEED_PAPER_TO_BLACK_BAR);
How to feed thermal paper one time–
public static byte[] FEED_LINE = {10};
mmOutputStream.write(FEED_LINE);
How to set underline Mode in Thermal Printer–
public static byte[] SET_UNDERLINE_MODE_OFF = {0x1B, 0x2D, 1}; // for underline mode off
mmOutputStream.write(SET_UNDERLINE_MODE_OFF);
Now for single underline following command is used–
public static byte[] SET_UNDERLINE_MODE_ON_1DOT_WIDTH = {0x1B, 0x2D, 1};
mmOutputStream.write(SET_UNDERLINE_MODE_ON_1DOT_WIDTH);
Now for double underline following command is used–
public static byte[] SET_UNDERLINE_MODE_ON_2DOT_WIDTH = {0x1B, 0x2D, 2};
mmOutputStream.write(SET_UNDERLINE_MODE_ON_2DOT_WIDTH);
How to set Emphasized Mode/Bold Mode in Thermal Printer-
public static byte[] SET_EMPHASIZED_MODE_OFF = {0x1B, 0x45, 0}; // for Normal Print
mmOutputStream.write(SET_EMPHASIZED_MODE_OFF);
public static byte[] SET_EMPHASIZED_MODE_ON = {0x1B, 0x45, 1}; // for BOLD print
mmOutputStream.write(SET_EMPHASIZED_MODE_ON);
How to set Alignment for printing on Thermal Paper–
public static byte[] LEFT_JUSTIFICATION = {0x1B, 0x61, 0}; // for left alignment
mmOutputStream.write(LEFT_JUSTIFICATION);
public static byte[] CENTER_JUSTIFICATION = {0x1B, 0x61, 1}; // for center alignment
mmOutputStream.write(CENTER_JUSTIFICATION);
public static byte[] RIGHT_JUSTIFICATION = {0x1B, 0x61, 2}; // for right alignment
mmOutputStream.write(RIGHT_JUSTIFICATION);
Pingback: What is Thermal printer - R S Trading & Service
Pingback: What is advantage of Thermal Printer -R S Trading & Service
Pingback: Do Thermal Printer works well? - R S Trading & Service
Pingback: How to print on Thermal Printer programmatically - R S Trading & Service