ESC/POS Commands
ESC/POS is a thermal printer command set developed by Epson. It is the industry standard for POS printers and offers the best compatibility.
Overview
Section titled “Overview”Like ESC, ESC/POS uses binary control commands. Its broad industry adoption makes it the preferred choice for receipt printing.
Comparison with ESC
Section titled “Comparison with ESC”| Feature | ESC | ESC/POS |
|---|---|---|
| Command format | Binary | Binary |
| Industry standard | No | ✅ Epson standard |
| Compatibility | Average | Excellent |
| Primary use | Portable printers | Point-of-sale systems |
Character encoding
Section titled “Character encoding”Printer control commands
Section titled “Printer control commands”Initialize the printer (ESC @)
Section titled “Initialize the printer (ESC @)”Initialize the printer, clear the print buffer, and restore default settings.
ESC @Hex: 1B 40Print and line feed (LF)
Section titled “Print and line feed (LF)”Print the buffer contents and advance to the next line.
LFHex: 0APrint and carriage return (CR)
Section titled “Print and carriage return (CR)”Print the buffer contents and return the carriage.
CRHex: 0DFeed paper (ESC J)
Section titled “Feed paper (ESC J)”Feed the paper forward by n units.
ESC J nHex: 1B 4A n| Parameter | Range | Description |
|---|---|---|
| n | 0-255 | Feed distance in dots |
Feed n lines (ESC d)
Section titled “Feed n lines (ESC d)”Feed the paper forward by n lines.
ESC d nHex: 1B 64 n| Parameter | Range | Description |
|---|---|---|
| n | 0-255 | Number of lines to feed |
Text formatting commands
Section titled “Text formatting commands”Set character size (GS !)
Section titled “Set character size (GS !)”Set the character width and height multipliers.
GS ! nHex: 1D 21 nBit settings for parameter n:
- Bits 0–2: Horizontal multiplier (0–7 represents 1–8 times)
- Bits 4–6: Vertical multiplier (0–7 represents 1–8 times)
| n value | Effect |
|---|---|
0x00 | Normal size (1x1) |
0x10 | Double height (1x2) |
0x01 | Double width (2x1) |
0x11 | Double width and height (2x2) |
0x22 | Triple width and height (3x3) |
0x77 | 8× width and height (8x8) |
Example:
1D 21 11 // Set width and height multipliersSet alignment (ESC a)
Section titled “Set alignment (ESC a)”Set text alignment.
ESC a nHex: 1B 61 n| n value | Alignment |
|---|---|
| 0 | Left aligned |
| 1 | Centered |
| 2 | Right aligned |
Example:
1B 61 01 // Center alignedSet bold (ESC E)
Section titled “Set bold (ESC E)”Enable or disable bold mode.
ESC E nHex: 1B 45 n| n value | Effect |
|---|---|
| 0 | Disable bold |
| 1 | Enable bold |
Set underline (ESC -)
Section titled “Set underline (ESC -)”Set underline mode.
ESC - nHex: 1B 2D n| n value | Effect |
|---|---|
| 0 | Disable underline |
| 1 | 1-dot underline |
| 2 | 2-dot underline |
Set reverse printing (GS B)
Section titled “Set reverse printing (GS B)”Set black/white reverse printing mode.
GS B nHex: 1D 42 n| n value | Effect |
|---|---|
| 0 | Disable reverse printing |
| 1 | Enable reverse printing |
Set font (ESC M)
Section titled “Set font (ESC M)”Select the font type.
ESC M nHex: 1B 4D n| n value | Font |
|---|---|
| 0 | Font A (12x24) |
| 1 | Font B (9x17) |
Set line spacing (ESC 3)
Section titled “Set line spacing (ESC 3)”Set the line spacing.
ESC 3 nHex: 1B 33 n| Parameter | Description |
|---|---|
| n | Line spacing (dots) |
Restore default line spacing (ESC 2)
Section titled “Restore default line spacing (ESC 2)”Restore the default line spacing.
ESC 2Hex: 1B 32Barcode printing commands
Section titled “Barcode printing commands”Set barcode height (GS h)
Section titled “Set barcode height (GS h)”Set the barcode height.
GS h nHex: 1D 68 n| Parameter | Range | Description |
|---|---|---|
| n | 1-255 | Barcode height (dots) |
Example:
1D 68 50 // Set barcode height to 80 DotsSet barcode width (GS w)
Section titled “Set barcode width (GS w)”Set the barcode width.
GS w nHex: 1D 77 n| Parameter | Range | Description |
|---|---|---|
| n | 2-6 | Barcode width multiplier |
Set HRI character position (GS H)
Section titled “Set HRI character position (GS H)”Set the printing position of human-readable interpretation (HRI) characters for the barcode.
GS H nHex: 1D 48 n| n value | Position |
|---|---|
| 0 | Do not print |
| 1 | Above barcode |
| 2 | Below barcode |
| 3 | Above and below |
Print a barcode (GS k)
Section titled “Print a barcode (GS k)”Print a one-dimensional barcode.
GS k m n [Data]Hex: 1D 6B m n [Data]| Parameter | Description |
|---|---|
| m | Barcode type |
| n | Data length |
Barcode type
Section titled “Barcode type”| m value | Barcode type | Data requirements |
|---|---|---|
| 0 | UPC-A | 11-12 digits |
| 1 | UPC-E | 6-8 digits |
| 2 | EAN-13 | 12-13 digits |
| 3 | EAN-8 | 7-8 digits |
| 4 | CODE39 | Alphanumeric |
| 5 | ITF | Even number of digits |
| 6 | CODABAR | Digits + A-D |
| 65 | UPC-A | 11-12 digits |
| 66 | UPC-E | 6-8 digits |
| 67 | EAN-13 | 12-13 digits |
| 68 | EAN-8 | 7-8 digits |
| 69 | CODE39 | Alphanumeric |
| 70 | ITF | Even number of digits |
| 71 | CODABAR | Digits + A-D |
| 72 | CODE93 | ASCII |
| 73 | CODE128 | ASCII (recommended) |
Example:
1D 68 60 // Set barcode height 961D 77 03 // Set barcode width 31D 48 02 // HRI Print below1D 6B 49 0D 7B 42 31 32 33 34 35 36 37 38 39 30 31 32 33 // Print CODE128 Barcode "1234567890123"QR code printing commands
Section titled “QR code printing commands”QR code printing steps
Section titled “QR code printing steps”QR code printing requires several commands in sequence:
1. Set cell size (GS ( k)
Section titled “1. Set cell size (GS ( k)”GS ( k pL pH cn fn nHex: 1D 28 6B 03 00 31 43 n| Parameter | Range | Description |
|---|---|---|
| n | 1-16 | Cell size (dots) |
2. Set error correction level (GS ( k)
Section titled “2. Set error correction level (GS ( k)”GS ( k pL pH cn fn nHex: 1D 28 6B 03 00 31 45 n| n value | Error correction level | Error correction capacity |
|---|---|---|
| 48 (0x30) | L | 7% |
| 49 (0x31) | M | 15% |
| 50 (0x32) | Q | 25% |
| 51 (0x33) | H | 30% |
3. Store data (GS ( k)
Section titled “3. Store data (GS ( k)”GS ( k pL pH cn fn m [Data]Hex: 1D 28 6B pL pH 31 50 30 [Data]| Parameter | Description |
|---|---|
| pL pH | Data length + 3 (low byte, high byte) |
| Data | QR code content |
4. Print (GS ( k)
Section titled “4. Print (GS ( k)”GS ( k pL pH cn fn mHex: 1D 28 6B 03 00 31 51 30Complete example:
1D 28 6B 03 00 31 43 06 // Set cell size to 61D 28 6B 03 00 31 45 31 // Set error correction level to M1D 28 6B 13 00 31 50 30 68 74 74 70 73 3A 2F 2F 65 78 61 6D 70 6C 65 2E 63 6F 6D // Store data "https://example.com"1D 28 6B 03 00 31 51 30 // Print a QR codePaper cutting commands
Section titled “Paper cutting commands”Full cut (GS V)
Section titled “Full cut (GS V)”Perform a full cut.
GS V mHex: 1D 56 m| m value | Effect |
|---|---|
| 0 | Full cut |
| 1 | Partial cut |
Feed and cut (GS V)
Section titled “Feed and cut (GS V)”Feed n lines and then cut the paper.
GS V m nHex: 1D 56 m n| m value | Effect |
|---|---|
| 65 (0x41) | Feed n lines, then full cut |
| 66 (0x42) | Feed n lines, then partial cut |
Example:
1D 56 42 03 // Feed paper 3 Lines, then cutImage printing commands
Section titled “Image printing commands”Print a raster bitmap (GS v 0)
Section titled “Print a raster bitmap (GS v 0)”Print a raster bitmap image.
GS v 0 m xL xH yL yH [Data]Hex: 1D 76 30 m xL xH yL yH [Data]| Parameter | Description |
|---|---|
| m | Print mode (0=Normal, 1=Double width, 2=Double height, 3=Double width and height) |
| xL xH | Horizontal byte count (Width/8) |
| yL yH | Vertical dot count (Height) |
| Data | Bitmap data |
Cash drawer commands
Section titled “Cash drawer commands”Open the cash drawer (ESC p)
Section titled “Open the cash drawer (ESC p)”Open the cash drawer.
ESC p m t1 t2Hex: 1B 70 m t1 t2| Parameter | Description |
|---|---|
| m | Cash drawer pin (0 or 1) |
| t1 | On time (t1 × 2ms) |
| t2 | Off time (t2 × 2ms) |
Example:
1B 70 00 19 FA // Open the cash drawerStatus query commands
Section titled “Status query commands”Query printer status (DLE EOT)
Section titled “Query printer status (DLE EOT)”Query printer status in real time.
DLE EOT nHex: 10 04 n| n value | Query target |
|---|---|
| 1 | Printer status |
| 2 | Offline status |
| 3 | Error status |
| 4 | Paper status |
Complete receipt example
Section titled “Complete receipt example”Example command sequence
Section titled “Example command sequence”1B 40 // Initialize the printer
// Print title1B 61 01 // Centered1D 21 11 // Double width and height[GBK: XX Convenience store]0A
// Print subtitle1D 21 00 // Restore normal size[GBK: Order number: 20240115001]0A[GBK: ================================]0A
// Print product list1B 61 00 // Left aligned[GBK: Cola 500ml x2 ¥6.00]0A[GBK: Potato chips Large pack x1 ¥8.50]0A[GBK: Mineral water x3 ¥4.50]0A[GBK: --------------------------------]0A
// Print total1D 21 10 // Double height1B 45 01 // Bold[GBK: Total: ¥19.00]1B 45 00 // Disable bold1D 21 00 // Restore normal mode0A 0A
// Print a QR code1B 61 01 // Centered1D 28 6B 03 00 31 43 05 // QR code cell size1D 28 6B 03 00 31 45 31 // Error correction level M1D 28 6B ... 31 50 30 [URLData] // Store data1D 28 6B 03 00 31 51 30 // Print a QR code[GBK: Scan to follow the store]0A
// Print a barcode1D 68 50 // Barcode height1D 77 02 // Barcode width1D 48 02 // HRI Position1D 6B 49 ... [Barcode data] // Print a barcode
// Feed and cut1B 64 03 // Feed paper 3 Lines1D 56 42 00 // Cut paperReceipt structure
Section titled “Receipt structure”┌─────────────────────────────┐│ XX Convenience store │ ← Centered, Double width and height│ Order number: 20240115001 │ ← Centered, Normal size│ ════════════════════════════││ Cola 500ml x2 ¥6.00 │ ← Left aligned│ Potato chips Large pack x1 ¥8.50 ││ Mineral water x3 ¥4.50 ││ ────────────────────────────││ Total: ¥19.00 │ ← Double height, Bold│ ││ [QR code] │ ← Centered│ Scan to follow the store ││ ││ ||||||||||||||| │ ← Barcode│ 6901234567890 │└─────────────────────────────┘SDK integration
Section titled “SDK integration”For ESC/POS usage in each language, see:
- Dart SDK - Cross-platform Flutter development
- Java SDK - Native Android development
- JavaScript SDK - Mini Program development
- OpenHarmony SDK - HarmonyOS / OpenHarmony applications
- Objective-C SDK - Native iOS development
- Swift SDK - iOS/macOS development