Class 'Mpdf\Mpdf' not found
-
15-04-2021 - |
Question
I am trying to install the magento2-pdf-generator2 extension, but I first need to install the mpdf library, I ran the composer require mpdf/mpdf
command and then ran php bin/magento setup:upgrade
and php bin/magento setup:static-content:deploy
to clear the caches.
I tried the following example example and put it in a file called test1.php in the root directory:
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();
But I am getting an error:
[31-May-2017 16:30:00 UTC] PHP Fatal error: Uncaught Error: Class 'Mpdf\Mpdf' not found in /home/public_html/test1.php:4
Stack trace:
#0 {main}
thrown in /home/public_html/test1.php on line 4
all that I have in my test file is:
<?php
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();
?>
I do have the mbstring, gd, zlib and bcmath extensions enabled. I am unsure why it isn't loading
Solution
try code below
$mpdf = new \mPDF('utf-8', 'A4-L');
OTHER TIPS
composer require mpdf/mpdf
php bin/magento setup:upgrade
For Magento version 2.0.x to 2.1.x - php bin/magento setup:static-content:deploy
For Magento version 2.2.x & above - php bin/magento setup:static-content:deploy –f
php bin/magento cache:flush
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange