mPDF › Getting mPDF
Getting mPDF
mPDF is no longer distributed as ZIP files. The current version is installed with Composer, which also installs its dependencies and keeps it up to date. We don’t host any mPDF files: get them from the official sources below.
Install with Composer
If you don’t have Composer yet, follow the instructions at getcomposer.org. Then, in your project folder:
composer require mpdf/mpdfLoad it with Composer’s autoloader and you’re ready:
<?php
require __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf(['tempDir' => sys_get_temp_dir() . '/mpdf']);
$mpdf->WriteHTML('<h1>It works</h1>');
$mpdf->Output();The install guide covers the PHP extensions mPDF needs and how to set up the temp folder.
Releases and changes
- The package page on Packagist lists every version and its requirements.
- Release notes and the changelog are in the project’s GitHub repository.
To upgrade a project, run composer update mpdf/mpdf and read the changelog for anything marked as a breaking change.
Still using mPDF 5 or 6?
The old ZIP releases (5.x and 6.0) were last updated around 2015–2016. They rely on PHP features that were removed long ago, so they fail on current PHP, and they miss years of security fixes. Upgrading is mostly mechanical:
| Old (5.x / 6.0) | Now (7.x / 8.x) |
|---|---|
include 'mpdf/mpdf.php'; | require 'vendor/autoload.php'; |
new mPDF('utf-8', 'A4', 0, '', 15, 15, 16, 16) | new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4', 'margin_left' => 15, …]) |
Editing config.php inside the library | Passing options in the constructor array |
Fonts registered in config_fonts.php | fontDir and fontdata options (how) |
$mpdf->Output('file.pdf', 'D') | Still works. Destination::DOWNLOAD is the named constant. |
The configuration guide maps every old constructor argument to its new key.
Don’t need PHP?
To turn a single HTML document into a PDF, you don’t need a library at all. Our HTML to PDF tool does it in your browser.