Guides › mPDF › Barcodes and QR codes

Barcodes and QR codes

Written for mPDF 8.2 on PHP 8.1+. Updated 2 November 2026.

mPDF draws barcodes as vector graphics with its own <barcode> tag, so they print sharply at any size and need no image files.

A product barcode

<barcode code="5012345678900" type="EAN13" />
<barcode code="036000291452" type="UPCA" />
<barcode code="INV-2026-041" type="C128A" />
<barcode code="PART 42" type="C39" />

Common types include EAN13, EAN8, UPCA, UPCE, ISBN, ISSN, the Code 128 family (C128A, C128B, C128C), C39, I25 and the postal formats. The check digit of an EAN or UPC code is validated, so a wrong digit is an error rather than a barcode that won’t scan.

Size and text

<barcode code="5012345678900" type="EAN13" size="0.8" height="1.2" text="1" />
  • size scales the whole barcode (1 is the standard size).
  • height stretches the bars only.
  • text shows or hides the human-readable digits (EAN and UPC show them by default).

QR codes

<barcode code="https://example.com/track/INV-2026-041" type="QR" size="0.9" error="M" disableborder="1" />
  • error sets the error-correction level: L, M, Q or H. Higher levels survive damage better but make denser codes. M suits most printed documents.
  • disableborder="1" removes the quiet-zone border mPDF adds. Only do that when the code already has white space around it.

If your installation reports a missing QR code class, add the companion package with composer require mpdf/qrcode.

Barcodes that scan

  1. Keep a quiet zone. Leave clear space either side of a linear barcode, at least ten times the narrowest bar.
  2. Don’t shrink below about 80% of nominal size for retail codes.
  3. Use dark bars on white. Coloured or reversed barcodes often fail on cheap scanners.
  4. Test the printed result with a phone, not just the PDF on screen.

Some barcode types do their maths with PHP’s bcmath extension. If a type fails to render, check that it is installed (php -m).