ESC/POS command reference › GS k
GS k (1D 6B): print EAN-13, UPC-A, CODE39 and CODE128 barcodes
The printer draws the barcode itself; you send its type and data. Set height, bar width and the human-readable text first with GS h, GS w and GS H.
| ASCII | GS k m n d1...dn |
| Hex | 1D 6B m n d1...dn |
| Decimal | 29 107 m n d1...dn |
Parameters
m | type. Form with length byte: 65 UPC-A, 66 UPC-E, 67 EAN-13 (JAN13), 68 EAN-8, 69 CODE39, 70 ITF, 71 Codabar, 72 CODE93, 73 CODE128. Older NUL-terminated form: 0 to 6 for the first seven types. |
n | number of data bytes (form with m 65 to 73 only). |
GS h n | 1D 68 n: barcode height in dots, 1 to 255. |
GS w n | 1D 77 n: module (narrow bar) width in dots. |
GS H n | 1D 48 n: human-readable text, 0 none, 1 above, 2 below, 3 both. |
What it does
There are two forms. With m = 65 to 73 the type is followed by a length byte and the data. With m = 0 to 6 the data ends with a 00 byte instead. escpos-php uses the length form when the printer profile supports it and falls back to the old form otherwise.
Data rules come from the barcode standards. escpos-php checks them before sending: UPC-A 11 or 12 digits, EAN-13 12 or 13, EAN-8 7 or 8, ITF an even number of digits, CODE39 digits, capitals and space $ % + - . /.
CODE128 data must start with a code set selector: {A, {B or {C (escpos-php refuses CODE128 data without one). {B covers ordinary text.
escpos-php notes that widths "above 6 appear to have no effect". A barcode wider than the paper does not print, and the viewer warns when that happens.
Example
EAN-13 and CODE128 (code set B), 80 dots high, text below.
1D 68 50 1D 77 02 1D 48 02 1B 61 01 1D 6B 43 0D 34 30 30 36 33 38 31 33 33 33 39 33 31 0A 1D 6B 49 09 7B 42 54 4C 2D 31 30 34 32 0A 1B 61 00
Preview drawn in your browser by the ESC/POS viewer's engine on 80 mm paper. Letters use a similar monospace font, not the printer's own. Open this example in the viewer to edit the bytes.
How the viewer decodes these bytes
| Command | What it does | Bytes |
|---|---|---|
| GS h | Barcode height 80 dots | 1D 68 50 |
| GS w | Barcode module width 2 | 1D 77 02 |
| GS H | Barcode text: below | 1D 48 02 |
| ESC a | Align center | 1B 61 01 |
| GS k | Barcode EAN-13 "4006381333931", 190 dots wide, 80 high | 1D 6B 43 0D 34 30 30 36 33 38 31 33 33 33 39 33 31 |
| GS k | Barcode CODE128 "TL-1042", 224 dots wide, 80 high | 1D 6B 49 09 7B 42 54 4C 2D 31 30 34 32 |
| ESC a | Align left | 1B 61 00 |
Sending it from code
JavaScript (bytes)
const data = [..."{BTL-1042"].map(c => c.charCodeAt(0));
const code128 = [0x1d, 0x68, 80, 0x1d, 0x48, 2, 0x1d, 0x6b, 73, data.length, ...data];PHP with escpos-php
$printer->setBarcodeHeight(80);
$printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW);
$printer->barcode("{BTL-1042", Printer::BARCODE_CODE128);Python (raw bytes)
d = b"4006381333931"
data += b"\x1d\x68\x50\x1d\x48\x02\x1d\x6b\x43" + bytes([len(d)]) + d
Common mistakes
- CODE128 without
{B: the first two characters are taken as the code set, or the printer prints nothing. - Wrong length byte
n: the printer takes too few bytes, or swallows the commands that follow. - A height of 8 dots (escpos-php's default when you call
setBarcodeHeight()with no value) is about 1 mm, too short for most scanners. Use 50 to 100.
Related commands
GS ( k: print a QR code on a receipt printerESC a: center or right-align text on a receipt printerGS v 0: print a logo or image on a receipt printer
Sources
- escpos-php,
Printer.php(MIT licence) - python-escpos,
constants.py(MIT licence) - Thermalink agent output, printed on a BIXOLON SRP-352plusIII (Windows 11, USB)
I wrote this page from the open-source libraries above, Thermalink's own output and tests on my BIXOLON printer. It is not copied from Epson's manual. For model-specific details see Epson's official ESC/POS reference or your printer maker's manual. Last checked 22 November 2026.
Building receipts byte by byte? Thermalink lets a web app send the receipt as JSON and prints it silently, with QR codes, logos, cut and cash drawer ($49 one-time).