mPDF Manual – Installation & Setup

Reducing memory usage

mPDF “Lite”

The mPDF main file mpdf.php is over 1MB in size. Simply to parse the mPDF class requires over 10MB of memory in PHP. This may not be a problem, but if your PHP configuration does not allow you to increase memory, or you envisage multiple calls on your server at the same time, you can consider producing a ‘Lite’ form of the mpdf.php script.

A utility script compress.php is included in mPDF in the root folder. This generates a new mpdf.php script omitting functions which you do not require. (It does not actually compress the file)

As from mPDF 6.0.1 this file will be distribtued as compress.php.distr to avoid other users running the file unwantedly. To use compress, just rename the file compress.php (and remember to delete or rename it after you have finished using it).

As a guideline:

 Version 5.1 Size of mpdf.php file Memory usage in PHP
Full script 1170kB 12.75MB
Omitting functions, but including: Tables, lists and images 697kB 7.0MB
Omitting all optional functions 496kB 5.25MB

Firstly, rename the mpdf.php file as mpdf_source.php

Then point your broswer to [path_to_mpdf]/compress.php

Follow the instructions on screen. This will produce (overwriting if necessary) a new mpdf.php file.

Do not delete the mpdf_source file, which will remain as your original.