withDeterministic(new DeterministicSettings( new DateTimeImmutable('2026-08-08T00:00:00Z'), \str_repeat('9', 32), )); $doc = Document::createStandalone($config); $doc->setTitle('GS1 Composite Capacity Boundaries'); $doc->setPrintFooter(false); $doc->addPage(); $doc->setFont('helvetica', 'B', 18); $doc->setXY(24, 20); $doc->cell(0, 12, 'GS1 Composite Capacity Boundaries', newLine: true); $caption = static function ( Document $document, float $x, float $y, string $cellId, string $boundary, string $payloadSummary, ): void { $publicCellId = \preg_replace('/^w[0-9]+-/', '', $cellId) ?? $cellId; $document->setFont('helvetica', '', 6.5); foreach ([ "CELL {$publicCellId}:", "GS1 Composite / version=auto {$boundary}", 'ECC=variant-defined', "payload={$payloadSummary}", ] as $line => $text) { $document->setXY($x, $y + ($line * 9)); $document->cell(260, 9, $text); } }; $renderComponent = static function ( Document $document, Barcode2DData $symbol, string $payload, float $x, float $pdfY, float $width, float $height, string $profile, ): void { $operators = (new BarcodeRenderer())->render2DInBox( data: $symbol, x: $x, y: $pdfY, w: $width, h: $height, fallbackModuleSize: 1.0, ); $components = (new CompositePlacementEmitter())->prepare([ new BarcodeComponentDrawSpec( kind: 'main', contentStream: $operators, bounds: new PlacementBounds($x, $pdfY, $width, $height), ), ]); $context = $document->createCommitContext( type: $symbol->type, rawPayload: $payload, rawRequest: BarcodeRawRequest::single($payload), canonicalPayload: CanonicalBarcodePayload::single($symbol->data), appearance: new BarcodeAppearance(), x: $x, y: $pdfY, width: $width, height: $height, optionsSnapshot: ['profile' => $profile], ); $document->commitComponents($components, $context); }; $capabilities = CapabilityRegistry::getInstance(); $requiredCapabilities = [ 'barcode.gs1-composite-cc-a', 'barcode.gs1-composite-cc-b', 'barcode.gs1-composite-cc-c', ]; $compositeAvailable = \class_exists(CompositeComponentA::class) && \class_exists(CompositeComponentB::class) && \class_exists(CompositeComponentC::class); foreach ($requiredCapabilities as $capability) { $compositeAvailable = $compositeAvailable && $capabilities->has($capability) && $capabilities->get($capability)->isAvailable(); } if ($compositeAvailable) { /** @var list $encoders */ $encoders = [new CompositeComponentA(), new CompositeComponentB(), new CompositeComponentC()]; /** * Select the smallest component that can encode the payload. Only a * capacity overflow advances to the next component; all other failures * remain visible to the caller. */ $selectComponent = static function (string $payload) use ($encoders): CompositeComponentResult { foreach ($encoders as $encoder) { try { return $encoder->encodeComponent($payload, [ 'carrierType' => CompositeCarrierType::GS1_128, ]); } catch (OverflowException) { continue; } } throw new OverflowException('GS1 Composite data exceeds the CC-C capacity.'); }; $aToBPayload = '10' . \str_repeat('!', 23); $aToB = $selectComponent($aToBPayload); $caption( $doc, 24, 275, 'w1-gs1-composite-cc-a-to-b-boundary', 'CC-A->CC-B', 'AI10 25-byte first CC-B payload', ); $renderComponent($doc, $aToB->barcode, $aToBPayload, 55, 500, 180, 100, $aToB->variant->value); $bToCPayload = '10' . \str_repeat('!', 147); $bToC = $selectComponent($bToCPayload); $caption( $doc, 310, 275, 'w1-gs1-composite-cc-b-to-c-boundary', 'CC-B->CC-C', 'AI10 149-byte first CC-C payload', ); $renderComponent($doc, $bToC->barcode, $bToCPayload, 330, 450, 180, 150, $bToC->variant->value); } $output = \getenv('NEXTPDF_SAMPLE_OUTPUT') ?: __DIR__ . '/../output/49-barcode-gs1-composite-boundaries.pdf'; $doc->save($output); if (!$compositeAvailable) { echo "SKIP: GS1 Composite capacity-boundary cells require nextpdf/pro\n"; } echo "Created: {$output}\n";