Datamatrix

Datamatrix barcode in PHP: square and rectangular shapes, encoding schemes, code examples and SVG output

Datamatrix is the matrix format of choice for marking small parts: the solid L-shaped finder and the alternating timing pattern along the other two edges give a reader the grid from a symbol only 10 modules square.

Six encoding schemes cover different payload shapes, from ASCII through the compacted C40, TXT and X12 sets to raw BASE256, and the encoder picks between them unless told otherwise. The GS1 variant prefixes the payload with FNC1 so the data reads as an element string.

Type Token

ItemValue
Type tokenDATAMATRIX
Enum caseBarcodeType::DATAMATRIX
Family2D
StandardISO/IEC 16022
Class\Com\Tecnick\Barcode\Type\Square\Datamatrix

Input

ItemValue
Character setany byte sequence
Lengthup to 3116 digits or 2335 ASCII characters
CheckReed-Solomon error correction, computed by the library
Extra parameters2 (see below)

Extra Parameters

Appended to the type token after commas, as in DATAMATRIX,R.

PositionMeaningValuesDefault
1symbol shapeS square, R rectangularS
2encoding schemeASCII, C40, TXT, X12, EDF, BASE256, or GS1ASCII

Examples

A square symbol

<?php

require_once __DIR__ . '/vendor/autoload.php';

$barcode = new \Com\Tecnick\Barcode\Barcode();
$bobj = $barcode->getBarcodeObj(
    type: 'DATAMATRIX',
    code: '0123456789',
    width: -4,
    height: -4,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

echo $bobj->getInlineSvgCode();

Datamatrix barcode encoding 0123456789

A rectangular symbol

$bobj = $barcode->getBarcodeObj(
    type: 'DATAMATRIX,R',
    code: '0123456789012345678901234567890123456789',
    width: -4,
    height: -4,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

Datamatrix barcode encoding 0123456789012345678901234567890123456789

GS1 mode, with FNC1 opening the element string

$bobj = $barcode->getBarcodeObj(
    type: 'DATAMATRIX,S,GS1',
    code: \chr(232) . '01095011010209171719050810ABCD1234' . \chr(232) . '2110',
    width: -4,
    height: -4,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

Datamatrix barcode encoding \xE801095011010209171719050810ABCD1234\xE82110

Errors

These payloads raise \Com\Tecnick\Barcode\Exception:

PayloadMessage
``Empty input

See Also