mPDF Manual – Troubleshooting

Corrupt PDF file

If you get a message saying “Corrupt PDF file: does not start with %PDF”, it may be because your script - either mPDF or an error in your PHP code - has output an error message. The browser is expecting a file in PDF format, which should start with %PDF and instead it gets some text like an error message.

To show error message(s):


$mpdf = new \Mpdf\Mpdf();
$mpdf->debug = true;

Also, you should always use try/catch block for a \Mpdf\MpdfException to find out more:

try {
    $mpdf = new \Mpdf\Mpdf();
    $mpdf->WriteHTML('Hello World');
    // Other code
} catch (\Mpdf\MpdfException $e) { // Note: safer fully qualified exception name used for catch
    // Process the exception, log, print etc.
    echo $e->getMessage();
Fork me on GitHub