CODE 128

CODE 128 barcode in PHP: automatic subset switching, character set, code example and SVG output

CODE 128 covers the full ASCII set across three subsets: A for control characters and upper case, B for the printable range including lower case, C for pairs of digits at one character per two. This type picks the subsets and the switches between them from the payload, which for numeric data means roughly half the width of CODE 39.

Where the subset has to be fixed, use C128A, C128B or C128C instead.

Type Token

ItemValue
Type tokenC128
Enum caseBarcodeType::C128
FamilyLinear
StandardISO/IEC 15417
Class\Com\Tecnick\Barcode\Type\Linear\CodeOneTwoEight

Input

ItemValue
Character setthe 128 ASCII characters
Length1 to 30000 characters
Checkmodulo 103, computed by the library
Extra parametersnone

Examples

Digits, which switch the encoder into subset C

<?php

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

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

echo $bobj->getInlineSvgCode();

CODE 128 barcode encoding 0123456789

Mixed case text

$bobj = $barcode->getBarcodeObj(
    type: 'C128',
    code: 'tc-lib-barcode',
    width: -3,
    height: -30,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

CODE 128 barcode encoding tc-lib-barcode

Errors

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

PayloadMessage
caf\xC3\xA9Invalid character sequence: 195

See Also