Data Matrix Barcode

GS k command has different parameters for Data Matrix 2D barcodes, as follows:

ASCII GS k n t r c m1 m2 dl….dm
Decimal 29 107 n t r c m1 m2 dl….dm
Hex 1D 6B n t r c m1 m2 dl….dm

Data Matrix barcodes are only supported for 203 x 203 dpi modes. They are not supported for 203 x 136 dpi modes.

Parameters

n

15 (0x0F)

t

option byte

Bit 7: “Numbers-only” compression.

Uses the ASCII number pairs compression in the Data Matrix specification. When this is enabled, only ASCII numbers may be sent to the printer. Any other data will be turned into the digit 0.

0: Compression disabled

1: Compression enabled

Bit 6: Exclude rectangles.

Excludes rectangular symbols for when the symbol size is being auto-selected. Only effective when r and c are both 0.

0: When symbol size is being auto-selected (r=c=0), a rectangular or square symbol may be chosen.

1: When symbol size is being auto-selected (r=c=0), only square symbols will be chosen.

Bit 5-0: Element size

The remaining 6 bits form a binary value for the size of the individual square elements in each Data Matrix symbol. This value is in units of the printers 203 dpi pixels. So, a value of 5 will result in each square element in the symbol being 5/203” wide and tall. If this value is set to 0, the printer will use its default value of 4.

r

the number of rows in the symbol.

If both r and c are 0, the printer will use the smallest supported Data Matrix symbol to store the data. Otherwise, this should be the desired number of rows, chosen from a supported symbol in the tables below.

c

the number of columns in the symbol.

If both r and c are 0, the printer will use the smallest supported Data Matrix symbol to store the data. Otherwise, this should be the desired number of columns, chosen from a supported symbol in the tables below.

m1 the most significant byte of data length.
m2 the least significant byte of data length.

Supported Square Data Matrix Symbol Sizes

Rows Columns Number of Encodable ASCII bytes Encodable numeric bytes with "Numbers-only" compression
10 10 3 6
14 14 8 16
18 18 18 36
22 22 30 60
26 26 44 88
36 36 86 172
44 44 144 288
52 52 204 408
72 72 368 736
88 88 576 1152
104 104 816 1632

Supported Rectangular Data Matrix Symbol Sizes

Rows Columns Number of Encodable ASCII bytes Encodable numeric bytes with "Numbers-only" compression
8 18 5 10
8 32 10 20
12 26 16 32
12 36 22 44
16 36 32 64
16 48 49 98

Examples

Encoding the numbers 12345, using numbers-only compression, and excluding rectangles. This should result in a 10x10 symbol.

GS ‘k’ 15 t r c m1 m2 dl…dm

GS 0x6B 0x0F 0xC0 0x00 0x00 0x00 0x05 0x3132333435

Prints the following image:

Here, 5 characters are also sent: ABCDE. However, since they are not all numbers, compression is not used. Rectangles are not excluded, so an 8x18 symbol should be auto-selected. The element size has been set to 5.

GS ‘k’ 15 t r c m1 m2 dl…dm

GS 0x6B 0x0F 0x05 0x00 0x00 0x00 0x05 0x4142434445

Prints the following image: