1
I’m trying to use the mpdf library to print in PDF. However, the following error is occurring when instantiating the library:
Fatal error: Trait 'Mpdf\Strict' not found in C:\wamp64\www\jlrw\PHP\transporte\app\lib\mPdf\src\Mpdf.php on line 44
I am not using framework. The mpdf library is in the folder: C:\wamp64\www\jlrw\PHP\transporte\app\lib
Follow the code I’m using in PHP:
session_start();
header('Content-Type: text/html; charset=utf-8');
$html = $_POST['dados'];
$sRoot = '..' . DIRECTORY_SEPARATOR;
require_once($sRoot . 'php' . DIRECTORY_SEPARATOR . 'definicoes.php');
// Aqui eu trago o arquivo principal da biblioteca
require_once($sRoot . 'lib' . DIRECTORY_SEPARATOR . 'mPdf' .
DIRECTORY_SEPARATOR . 'src' .
DIRECTORY_SEPARATOR . 'Mpdf.php');
// "Autoload"
function AutoLoad($classname) {
$filename = '..' .
DIRECTORY_SEPARATOR . 'lib' .
DIRECTORY_SEPARATOR . 'mPdf' .
DIRECTORY_SEPARATOR . 'src' .
DIRECTORY_SEPARATOR . $classname . '.php';
include_once($filename);
}
spl_autoload_register('AutoLoad');
$mpdf = new Mpdf();
$mpdf->WriteHTML($html);
$mpdf->Output();
echo 'Impressão realizada.';
At no time am I using namespace in my app. The version of my PHP is 7.2.4
The "Strict.php" file is in the "src" folder of the library. I don’t think it’s her mistake, but the way I’m trying to instate it for use.
I believe that the
mpdf
depends on the Composer (or equivalent) to load the internal classes. Neither Composer is using?– Woss
I didn’t get to use Poser either... I downloaded the library and put it in the folder. Is that the problem?
– Rodrigo Tognin
Yeah, see the source code from the library. In no time it imports the dependency files, leaving this responsibility to the tool of autoload who prefer.
– Woss
I installed mpdf via Composer inside my application and directly in the "lib/mpdf" folder, but now it gives another error when instantiating the object: "Uncaught Error: Class 'Mpdf' not found"... it’s strange...
– Rodrigo Tognin
You imported Composer autoload?
– Woss
Yes. I used the "require_once" command pointing directly to "autoload.php" inside the "vendor" folder that Composer created. I’m doing some more tests here. For now, thank you so much for your help.
– Rodrigo Tognin