Weave Code
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

Qrcode Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • PDF Workflow (mPDF): When generating PDFs with mPDF, inject the QR code using 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().
  • Responsive Web Embedding: Use Output\Html() with CSS to control display size (e.g., width: 100%; max-width: 200px). Avoid <canvas> — this library outputs base64-encoded PNG.
  • Batch Generation: For generating many QR codes (e.g., ticketing), preconfigure the QR instance once and reuse it — the generator caches internal data structures.
  • Form Integration: Pair with form submissions (e.g., RSVP or checkout confirmation) by encoding structured data:
    $qr = new QrCode(json_encode(['order_id' => $id, 'user' => $userId]));
    
  • Caching Strategy: Since QR codes are static, cache generated PNG/HTML output using Laravel’s cache system keyed by content hash to avoid redundant generation on repeat requests.

Gotchas and Tips

  • Error Correction Level Matters: By default, uses QrCode::ERROR_CORRECT_L. For printed materials (labels, tickets), consider M, Q, or H for robustness — e.g., $qr->setEccLevel(QrCode::ERROR_CORRECT_M);.
  • mPDF Output Specifics: Output\Mpdf() returns a string of HTML, not a resource or image object. Do not wrap it in <img> tags — it’s already embedded.
  • Data Size Limits: QR codes become unreadable if the payload is too large. For long payloads (e.g., full JSON), truncate or hash first — 2,000+ characters often exceeds practical scannability.
  • Debugging Quiet Zones: Ensure sufficient whitespace padding (->setMargin(10)) — many mobile scanners fail without it.
  • No Built-in Color Customization: PNG output is black-on-white only. For colored QR codes (e.g., brand-aligned), override Output\Png and modify internal GD resources — note this may break mPDF compatibility.
  • mPDF Compatibility: Ensure 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.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport