mPDF Manual – HTML control tags

barcode

(mPDF ≥ 4.0)

barcode – Add a Barcode to the document

Description

<barcode  $code [ $type ] [ $text ] [ $size ] [ $height ] [ $pr ] />

Add a Barcode to the document.

Attributes

$code

Specifies the code to translate to a barcode.

$code for EAN13 / ISBN / ISSN / UPCA / UPCE can contain hyphens (-) but no other characters are allowed.

Check-digits can be optionally included for EAN13 / ISBN / ISSN / UPCA / UPCE

REQUIRED

$type

$type specifies the type of barcode required.

Default: 'EAN13'

Values

  • 'EAN13', 'ISBN', 'ISSN', 'UPCA', 'UPCE', 'EAN8'
  • 'EAN13P2', 'ISBNP2', 'ISSNP2', 'UPCAP2', 'UPCEP2', 'EAN8P2' (with EAN-2 supplement code i.e. 01-99 )
  • 'EAN13P5', 'ISBNP5', 'ISSNP5', 'UPCAP5', 'UPCEP5', 'EAN8P5'  (with EAN-5 supplement code e.g. 90000 ) ('UPCE' needs the UPCA $code entered)
  • 'IMB', 'RM4SCC', 'KIX', 'POSTNET', 'PLANET'
  • 'C128A', 'C128B', 'C128C'
  • 'EAN128A', 'EAN128B', 'EAN128C'
  • 'C39', 'C39+', 'C39E', 'C39E+'
  • 'S25', 'S25+', 'I25', 'I25+', 'I25B', 'I25B+'
  • 'C93'
  • 'MSI', 'MSI+'
  • 'CODABAR'
  • 'CODE11'

Note: Type with a '+' at the end includes check-digits.

$text

EAN13 only

Specifies whether to show the code at the top of an EAN13 barcode.

Note that ISBN and ISSN always show the text, prefixed with ISBN or ISSN.

Values: 1 or 0

Default: 0

$size

Specifies the size of the barcode.

$size (float) will scale the nominal size of the barcode as a factor of 1

size="1.5" will generate a barcode one and half times the height and width of the nominal size set in mPDF

NB Sizes between '0.8' and '2.0' are recommended for EAN13 and similar barcodes.

Default: '1'

$height

Specifies the height of the barcode.

$height (float) will determine the relative height of the barcode as a factor of 1

The height factor is applied after the $size

size="2" height="0.5" will generate a barcode of twice the nominal width, but with the nominal height.

NB Ignored for Postcode barcodes

Default: '1'

$pr

Specifies the print ratio i.e. narrow:wide bar width for some types of barcode.

Valid for:

  • 'C39' (Code 39),
  • Standard and Interleaved 2 of 5 ('S25', 'I25' etc.),
  • 'CODABAR' and 'CODE11'

Default: Varies between 2.5 and 3.0 dependent on barcode specification (see barcodes)

Changelog

Version Description
4.0 The function was added.

Examples


<barcode code="978-0-9542246-0" type="ISBN" height="0.66" text="1" />


<barcode code="04210000526" type="UPCE" />
<!-- Note the UPC-A code is required which is converted to UPCE -->


<barcode code="978-0-9542246-0-8 07" type="ISSNP2" text="1" />


<barcode code="01234567094987654321-01234567891" type="IMB" />


<barcode code="SN34RD1A" type="RM4SCC" />


<barcode code="54321068" type="I25" />


<barcode code="A34698735B" type="CODABAR" />

Notes

Example with CSS

<style>
.barcode {
    padding: 1.5mm;
    margin: 0;
    vertical-align: top;
    color: #000044;
}
.barcodecell {
    text-align: center;
    vertical-align: middle;
}
</style>

<div class="barcodecell"><barcode code="54321068" type="I25" class="barcode" /></div>

Example - Generating a checkdigit

<?php

// Must not contain any - or spaces
include('../src/Barcode.php');

$bc = new \Mpdf\Barcode();
echo $bc->getChecksum('9344543204454', 'C93');

See Also

  • Barcodes - More information on types of barcode
Fork me on GitHub