phppdf-generationmpdf

Generating pdf in php using mpdf not working


I installed mpdf successfully via composer.

Here is my PHP code:

require_once __DIR__ . '/vendor/autoload.php';
$mpdf=new \Mpdf\Mpdf();
$mpdf->WriteHTML("<h1>test</h1>");
$file='abcd.pdf';
$mpdf->output($file,'I');

PDF won't generate. I tried in Chrome and Firefox. The location of autoload.php is correct. I tried D, F and S as well, as the second argument for $mpdf->output, none worked.


Solution

  • your code actually works, please double check your php version and note that mpdf is compatible only with PHP ≥ 5.6.0 and < 7.4.0.

    https://mpdf.github.io/about-mpdf/requirements-v7.html