Thermalink

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.

ASCIIGS k m n d1...dn
Hex1D 6B m n d1...dn
Decimal29 107 m n d1...dn

Parameters

mtype. 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.
nnumber of data bytes (form with m 65 to 73 only).
GS h n1D 68 n: barcode height in dots, 1 to 255.
GS w n1D 77 n: module (narrow bar) width in dots.
GS H n1D 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
CommandWhat it doesBytes
GS hBarcode height 80 dots1D 68 50
GS wBarcode module width 21D 77 02
GS HBarcode text: below1D 48 02
ESC aAlign center1B 61 01
GS kBarcode EAN-13 "4006381333931", 190 dots wide, 80 high1D 6B 43 0D 34 30 30 36 33 38 31 33 33 33 39 33 31
GS kBarcode CODE128 "TL-1042", 224 dots wide, 80 high1D 6B 49 09 7B 42 54 4C 2D 31 30 34 32
ESC aAlign left1B 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

Related commands

Sources

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).