mPDF Manual – Installation & Setup

Reducing memory usage

mPDF < 7.0

mPDF “Lite”

The mPDF main file mpdf.php is over 1 MB in size. Simply to parse the mPDF class requires over 10 MB 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 distributed 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 1170 kB 12.75 MB
Omitting functions, but including: Tables, lists and images 697 kB 7.0 MB
Omitting all optional functions 496 kB 5.25 MB

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

Then point your browser 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.

Fork me on GitHub