A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

v6.1.1 2016-04-28 18:19 UTC


mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF (see CREDITS), with a number of enhancements. mPDF was written by Ian Back and is released under the GNU GPL v2 licence.

Build Status

mPDF 7.0 requires PHP >=5.6.0. PHP mbstring extension must be loaded.


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

$ composer require mpdf/mpdf


The simplest usage of the library would be as follows:


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

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

This will output the HTML inline to the browser.

Setup & Configuration

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

It is recommended to set one's own temporary directory via tempDir and fontTempDir configuration variables. The directory must have write permissions (mode 775 is recommended).


$mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/tmp']);

By default, the temporary directory will be inside vendor directory and will have correct permissions from post_install composer script.

For more information about custom temporary directory see the note on Folder for temporary files in the section on Installation & Setup in the manual.

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

Online manual

Online manual is available at


See file in the project.

Unit Testing

Unit testing for mPDF is done using PHPUnit.

To get started, run composer install from the command line while in the mPDF root directory (you'll need composer installed first).

To execute tests, run vendor/bin/phpunit from the command line while in the mPDF root directory.

Any assistance writing unit tests for mPDF is greatly appreciated. If you'd like to help, please note that any PHP file located in the /tests/ directory will be autoloaded when unit testing.