CODE 39

CODE 39 barcode in PHP: character set, length limits, check character, code examples and SVG output

CODE 39 encodes digits, upper case letters and seven punctuation marks, one character per nine-element pattern of five bars and four spaces. Explicit start and stop characters delimit the symbol, so a scanner reads it without being told what to expect.

The format is wide. Ten characters occupy noticeably more space than the same ten in CODE 128, which is the usual reason for choosing something else.

Type Token

ItemValue
Type tokenC39
Enum caseBarcodeType::C39
FamilyLinear
StandardANSI MH10.8M-1983, USD-3, also known as 3 of 9
Class\Com\Tecnick\Barcode\Type\Linear\CodeThreeNine

Input

ItemValue
Character set0-9, A-Z, space, -, ., $, /, +, %. Lower case input is encoded as upper case.
Length1 to 30000 characters
Checknone. Use C39+ for the modulo 43 check character
Extra parametersnone

Examples

Digits

<?php

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

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

echo $bobj->getInlineSvgCode();

CODE 39 barcode encoding 0123456789

Letters and punctuation

$bobj = $barcode->getBarcodeObj(
    type: 'C39',
    code: 'TCPDF-2026/01',
    width: -3,
    height: -30,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

CODE 39 barcode encoding TCPDF-2026/01

Errors

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

PayloadMessage
abc!Invalid character: 33
TCPDF*The asterisk is reserved as the start/stop character

See Also