mPDF Manual – Installation & Setup

Installation v7+

Installation

Official installation method is via composer and its packagist package mpdf/mpdf.


$ composer require mpdf/mpdf

Usage

The simplest usage of the library would be as follows:

<?php

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();

All configuration directives can be set by the $config parameter of the constructor.

<?php
...
// Define a page using all default values except "L" for Landscape orientation
$mpdf = new \Mpdf\Mpdf(['orientation' => 'L']);
...

It is recommended to set custom temporary directory via tempDir configuration key. The directory must have write permissions (mode 775 is recommended).

<?php
// Define a page using all default values except "L" for Landscape orientation
$mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/custom/temp/dir/path']);

If you have problems, please read the section on troubleshooting in the manual.

Upgrading from older mPDF versions

mPDF 7.x has introduced namespaces, so in order to use mPDF, you have to reference the class either by fully qualified name:

<?php

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();

or import the class beforehand:

<?php

use Mpdf\Mpdf;

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new Mpdf();

The class now accepts only one parameter, an array of configuration directives. See configuration directives for reference.

If you wish to install additional fonts please see the notes in Fonts & Languages for further instructions.

Fork me on GitHub