mPDF Manual – mPDF functions

WriteBarcode()

(mPDF ≥ 2.0)

mPDF – Write an EAN-13 (ISBN-13) barcode

Description

void writeBarcode ( string $code [, int $showisbn [, float $x [, float $y [, float $size [, float $border [, float $padding_left , float $padding_right , float $padding_top , float $padding_bottom ]]]]]])

Write an EAN-13 barcode. Useful information about the EAN-13 (ISBN-13) specification can be found at http://www.gs1uk.org/downloads/bar_code/Bar coding getting it right.pdf

Parameters

$code

This parameter specifies the EAN-13 (ISBN-13) code. Accepts 12 or 13 digits (i.e. with or without the check digit) and may optionally contain hyphens e.g. 978-09542-2461-5  or  978095422461

$showisbn

Specify whether to show the EAN-13 (ISBN-13) code above the barcode. NB The numbers will always appear below the bars, but the code above the bars is optional.

Values

  • 1 (or any positive value): show the EAN-13 code
  • 0 (zero): Hide the EAN-13 code

BLANK or omitted: 1

$x

Sets the $x (horizontal) position for the barcode.

BLANK or omitted uses the current writing position in the document.

$y

Sets the $y (vertical) position for the barcode.

BLANK or omitted uses the current writing position in the document.

$size

This parameter specifies the size of the barcode relative to the standard. Values between 0.8 and 2.0 (80% to 200%) are accepted.

Default: 1

$border

This parameter specifies whether or not to show a border around the barcode.

Values

  • 1 or true (or any positive value) will set a border
  • 0 or false or BLANK will omit the border

Default: 0 i.e. No border

$padding_left
$padding_right
$padding_top
$padding_bottom

Sets the padding around the barcode.

All values should be specified as LENGTH in millimetres

BLANK or omitted uses the default values.

Default Values

  • $padding_left: 1
  • $padding_right: 1
  • $padding_top: 2
  • $padding_bottom: 2

Changelog

Version Description
2.0 The function was added.

Examples

<?php
$mpdf = new \Mpdf\Mpdf();

$mpdf->writeBarcode('978-1234-567-890');

$mpdf->Output();

Fork me on GitHub