Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Barcode Bundle Laravel Package

ticketpark/barcode-bundle

Symfony bundle for generating barcodes in your applications. Wraps popular barcode libraries behind a simple service, letting you render common formats like Code 128, EAN, QR and more, with support for SVG and PNG output and easy integration into templates and controllers.

View on GitHub
Deep Wiki
Context7

Getting Started

Install and enable (Symfony 2.x/3.x only).

composer require ticketpark/barcode-bundle

Register the bundle in app/AppKernel.php:

$bundles = [
    // ...
    new Ticketpark\BarcodeBundle\TicketparkBarcodeBundle(),
];

There is no Flex recipe and no Symfony 4+ support — see Gotchas. Open Resources/config/services.yml (or .xml) in the bundle first; that is the only reliable source of truth for the service ID (typically ticketpark_barcode.generator) and its constructor arguments. The generator wraps TCPDF's TCPDFBarcode/TCPDF2DBarcode classes, so all barcode type identifiers (C39, C128, EAN13, QRCODE, PDF417, DATAMATRIX, …) are the TCPDF constants, not bundle-specific ones.

First use case — a scannable QR code on a ticket/invoice:

$generator = $this->get('ticketpark_barcode.generator');
$barcode   = $generator->getBarcode('https://example.com/order/42', 'QRCODE');

return new Response($barcode->getPngData(), 200, [
    'Content-Type'        => 'image/png',
    'Content-Disposition' => 'inline; filename="qr.png"',
]);

Generate it once in a REPL/bin/console command first and eyeball the PNG before wiring a route. If the output is blank or a PHP notice is printed into the PNG stream, the TCPDF include path or the type string is wrong — that is the most common first-run failure.

Implementation Patterns

Dedicated, cacheable route. Do not inline generation into every page render. Expose one controller action keyed on a signed/id payload and let HTTP caching do the work — barcodes are deterministic for a given text/type/size.

/**
 * @Route("/barcode/{type}/{payload}", requirements={"payload"=".+"})
 */
public function barcodeAction(string $type, string $payload)
{
    $barcode  = $this->get('ticketpark_barcode.generator')->getBarcode($payload, $type);
    $response = new Response($barcode->getPngData(), 200, ['Content-Type' => 'image/png']);
    $response->setPublic();
    $response->setMaxAge(86400);
    $response->setETag(md5($type.$payload));
    return $response;
}

Embedding in HTML / emails as a data URI — avoids the extra HTTP round-trip and works in mail clients that block remote images poorly:

$png   = $generator->getBarcode($order->getNumber(), 'C128')->getPngData();
$src   = 'data:image/png;base64,'.base64_encode($png);
// <img src="{{ src }}" alt="Order {{ order.number }}">

Label/PDF pipelines. For Dompdf, TCPDF, or wkhtmltopdf, write the PNG to a temp path and reference it as a local file; embedding binary via data: in PDF renderers is hit-or-miss:

$path = $this->getParameter('kernel.cache_dir').'/label-'.$order->getId().'.png';
file_put_contents($path, $generator->getBarcode($sku, 'C128')->getPngData());

Batch generation in a console command for product labels or ticket books. Chunk the iteration (e.g. 200 at a time) and call gc_collect_cycles() between chunks — TCPDF leaks memory across repeated TCPDF2DBarcode instantiations, and QR codes are the expensive case.

Twig helper. A thin BarcodeExtension that returns the data URI is usually cleaner than calling the service in templates:

public function barcodeDataUri(string $text, string $type = 'C128'): string
{
    $png = $this->generator->getBarcode($text, $type)->getPngData();
    return 'data:image/png;base64,'.base64_encode($png);
}

Testing. The generator is a thin wrapper over a static-ish TCPDF API, so mock the service in controller/functional tests and assert the PNG magic bytes (\x89PNG) on integration tests. Do not assert byte-for-byte equality — TCPDF output can shift across dependency bumps.

Gotchas and Tips

It is abandoned. Last release 2018, zero dependents, and it depends on the Symfony 2 bundle system (Bundle subclass, XML service definitions, AppKernel registration). On Symfony 4+ there is no AppKernel, so you must either register it manually as a service in config/services.yaml and skip the bundle class entirely, or switch to a maintained library (endroid/qr-code for QR, picqer/php-barcode-generator for 1D). For any new project, take the second option.

Input validation is on you. TCPDF will happily render a wrong or unreadable barcode if you feed it invalid data: EAN13 requires exactly 12–13 digits with a valid checksum, C128 has an ASCII range limit, and UPC/EAN types reject letters. Validate with a regex per type before calling the generator and throw a domain exception rather than emitting a broken image.

Sizing and error correction are TCPDF options, not bundle config. QR error-correction level, module size, and the 1D bar width/height are passed through the TCPDF constructor. The bundle may expose some of these via a config block or a third argument to getBarcode — check DependencyInjection/Configuration.php in the bundle, because the README (if any) does not document them consistently across versions.

PNG only. getPngData() is the practical output. SVG is not available in the versions shipping with this bundle; if you need vector output for print labels, plan on a different generator.

No autowiring. The service is registered under a string ID (ticketpark_barcode.generator) with no class alias, so constructor injection by type will fail on modern Symfony. Either fetch it via the container, or add your own alias:

services:
    Ticketpark\BarcodeBundle\Generator\BarcodeGenerator:
        alias: ticketpark_barcode.generator

Debugging blank or corrupt output. TCPDF emits PHP warnings directly into the byte stream. If getPngData() returns garbage, it is almost always an undefined index inside TCPDF triggered by an unexpected type string or option; call ob_start() before generation and inspect. Also confirm ext-gd is installed — TCPDF silently degrades without it.

Version pinning. Pin ticketpark/barcode-bundle and tecnickcom/tcpdf explicitly in composer.json. TCPDF's own API has had breaking bumps, and an unpinned minor release can change the constructor signature this bundle wraps.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route