withDeterministic(new DeterministicSettings( new DateTimeImmutable('2026-07-24T00:00:00Z'), \str_repeat('7', 32), )); $doc = Document::createStandalone($config); $doc->setTitle('Barcode 2D Sample Sheet'); $doc->setPrintFooter(false); $doc->addPage(); $doc->setFont('helvetica', 'B', 18); $doc->setXY(24, 20); $doc->cell(0, 12, 'Barcode 2D Sample Sheet', newLine: true); $caption = static function ( Document $document, float $x, string $cellId, string $symbologyAndVersion, string $ecc, string $payload, ): void { $publicCellId = \preg_replace('/^w[0-9]+-/', '', $cellId) ?? $cellId; $document->setFont('helvetica', '', 6.5); foreach (["CELL {$publicCellId}:", $symbologyAndVersion, "ECC={$ecc}", "payload={$payload}"] as $line => $text) { $document->setXY($x, 55 + ($line * 9)); $document->cell(135, 9, $text); } }; $captionAt = static function ( Document $document, float $x, float $y, string $cellId, string $symbologyAndVersion, string $ecc, string $payload, ): void { $publicCellId = \preg_replace('/^w[0-9]+-/', '', $cellId) ?? $cellId; $document->setFont('helvetica', '', 6.5); foreach (["CELL {$publicCellId}:", $symbologyAndVersion, "ECC={$ecc}", "payload={$payload}"] as $line => $text) { $document->setXY($x, $y + ($line * 9)); $document->cell(135, 9, $text); } }; $caption($doc, 24, 'w1-aztec-plain', 'Aztec / version=auto', '23-percent', 'NEXTPDF-AZTEC'); $doc->write2DBarcode('NEXTPDF-AZTEC', Barcode2DType::Aztec, x: 35, y: 100, w: 105, h: 105); $caption($doc, 164, 'w1-aztec-rune', 'Aztec Rune / version=rune', 'fixed', '42'); $doc->write2DBarcodeWithOptions( '42', Barcode2DType::Aztec, symbolOptions: new AztecOptions(rune: true), x: 180, y: 100, w: 105, h: 105, ); $capabilities = CapabilityRegistry::getInstance(); $maxiCodeAvailable = $capabilities->has('barcode.maxicode') && $capabilities->get('barcode.maxicode')->isAvailable(); if ($maxiCodeAvailable) { $caption($doc, 304, 'w1-maxicode-mode4', 'MaxiCode / version=mode-4', 'standard', 'NEXTPDF-MAXICODE'); $doc->write2DBarcodeWithOptions( 'NEXTPDF-MAXICODE', Barcode2DType::MaxiCode, symbolOptions: new MaxiCodeOptions(mode: MaxiCodeMode::Mode4), x: 320, y: 100, w: 105, h: 105, ); } $microPdf417Available = $capabilities->has('barcode.micropdf417') && $capabilities->get('barcode.micropdf417')->isAvailable(); if ($microPdf417Available) { $caption($doc, 444, 'w1-micropdf417', 'MicroPDF417 / version=auto', 'version-defined', 'NEXTPDF'); $doc->write2DBarcodeWithOptions( 'NEXTPDF', Barcode2DType::MicroPDF417, symbolOptions: new MicroPdf417Options(), x: 460, y: 100, w: 105, h: 105, ); } if ($maxiCodeAvailable) { $maxiCodeCells = [ [ 'id' => 'w2-maxicode-mode2', 'mode' => MaxiCodeMode::Mode2, 'payload' => 'NEXTPDF-MAXICODE-2', 'postalCode' => '123456789', 'x' => 35.0, 'captionX' => 24.0, 'ecc' => 'standard', ], [ 'id' => 'w2-maxicode-mode3', 'mode' => MaxiCodeMode::Mode3, 'payload' => 'NEXTPDF-MAXICODE-3', 'postalCode' => 'ABC123', 'x' => 180.0, 'captionX' => 164.0, 'ecc' => 'standard', ], [ 'id' => 'w2-maxicode-mode5', 'mode' => MaxiCodeMode::Mode5, 'payload' => 'NEXTPDF-MAXICODE-5', 'postalCode' => null, 'x' => 320.0, 'captionX' => 304.0, 'ecc' => 'enhanced', ], [ 'id' => 'w2-maxicode-mode6', 'mode' => MaxiCodeMode::Mode6, 'payload' => 'NEXTPDF-MAXICODE-6', 'postalCode' => null, 'x' => 460.0, 'captionX' => 444.0, 'ecc' => 'standard', ], ]; foreach ($maxiCodeCells as $cell) { $mode = $cell['mode']; $captionAt( $doc, $cell['captionX'], 230, $cell['id'], 'MaxiCode / version=mode-' . $mode->value, $cell['ecc'], $cell['payload'], ); $doc->write2DBarcodeWithOptions( $cell['payload'], Barcode2DType::MaxiCode, symbolOptions: new MaxiCodeOptions( mode: $mode, postalCode: $cell['postalCode'], countryCode: $cell['postalCode'] === null ? null : '840', serviceClass: $cell['postalCode'] === null ? null : '001', ), x: $cell['x'], y: 275, w: 105, h: 105, ); } } $captionAt($doc, 24, 430, 'w2-aztec-eci', 'Aztec / version=ECI-26', '23-percent', 'NEXTPDF-AZTEC-ECI'); $doc->write2DBarcodeWithOptions( 'NEXTPDF-AZTEC-ECI', Barcode2DType::Aztec, symbolOptions: new AztecOptions(eci: 26), x: 35, y: 475, w: 105, h: 105, ); $gs1Available = $capabilities->has('barcode.gs1') && $capabilities->get('barcode.gs1')->isAvailable() && \class_exists('NextPDF\\Pro\\Barcode\\Gs1\\Gs1DataParser'); $gs1Payload = '(01)09501101530003(17)260101'; if ($gs1Available) { $captionAt($doc, 164, 430, 'w2-aztec-gs1', 'Aztec / version=GS1', '23-percent', $gs1Payload); $doc->write2DBarcodeWithOptions( $gs1Payload, Barcode2DType::Aztec, symbolOptions: new AztecOptions(gs1: true), x: 180, y: 475, w: 105, h: 105, ); } $captionAt($doc, 304, 430, 'w2-dmre-iso21471', 'Data Matrix / version=DMRE-8x48', 'ECC200', 'NEXTPDF-DMRE'); $doc->write2DBarcodeWithOptions( 'NEXTPDF-DMRE', Barcode2DType::DataMatrix, symbolOptions: new DataMatrixOptions( sizeProfile: DataMatrixSizeProfile::Iso21471Dmre, symbolSize: '8x48', ), x: 320, y: 475, w: 120, h: 60, ); $output = \getenv('NEXTPDF_SAMPLE_OUTPUT') ?: __DIR__ . '/../output/43-barcode-2d.pdf'; $doc->save($output); if (!$maxiCodeAvailable) { echo "SKIP: w1-maxicode-mode4 requires nextpdf/pro\n"; } if (!$microPdf417Available) { echo "SKIP: w1-micropdf417 requires nextpdf/pro\n"; } if (!$gs1Available) { echo "SKIP: w2-aztec-gs1 requires nextpdf/pro barcode.gs1\n"; } echo "Created: {$output}\n";