mpdf/qrcode
Laravel-friendly QR code generator for mPDF: create QR codes as images/data URIs and embed them in PDFs. Simple API for sizing, error correction, and output formats—ideal for invoices, tickets, and labels.
This package provides a simple, lightweight QR code generator that supports multiple output formats — PNG, HTML, and direct embedding into PDFs via mPDF. To begin, install it via Composer:
composer require mpdf/qrcode
The library is PSR-4 autoloaded — no additional bootstrap needed. The primary entry point is the QrCode class (from the Mpdf\QrCode namespace). A minimal usage example:
use Mpdf\QrCode\QrCode;
use Mpdf\QrCode\Output;
$qr = new QrCode('https://example.com');
$png = (new Output\Png())->output($qr, ['size' => 200]);
file_put_contents('qrcode.png', $png);
For immediate visual feedback in a web context, use Output\Html() to embed the QR code inline. For PDF reports or invoices, integrate directly with mPDF using Output\Mpdf() — see the “Implementation Patterns” section.
Mpdf\Output\Mpdf::output($qr, $mpdf) — this returns an mPDF-compatible HTML fragment (e.g., <img src="data:image/png;base64,...">) safe to embed in WriteHTML().Output\Html() with CSS to control display size (e.g., width: 100%; max-width: 200px). Avoid <canvas> — this library outputs base64-encoded PNG.$qr = new QrCode(json_encode(['order_id' => $id, 'user' => $userId]));
QrCode::ERROR_CORRECT_L. For printed materials (labels, tickets), consider M, Q, or H for robustness — e.g., $qr->setEccLevel(QrCode::ERROR_CORRECT_M);.Output\Mpdf() returns a string of HTML, not a resource or image object. Do not wrap it in <img> tags — it’s already embedded.->setMargin(10)) — many mobile scanners fail without it.Output\Png and modify internal GD resources — note this may break mPDF compatibility.mPDF/mpdf is installed after this package — mPDF uses its own QR code support in newer versions, and conflicts can occur if both libraries attempt to define QrCode. Check version compatibility.How can I help you explore Laravel packages today?