Mian Saeed Akbar
Mian Saeed Akbar

Reputation: 99

mpdf not working [Fatal error: Trait 'Mpdf\Strict' not found]

I have downloaded the updated version of mpdf and using it with php. It is giving me the following error.

"fatal error: Trait 'Mpdf\Strict' not found in E:\xampp\htdocs\PDF\mpdf\Mpdf.php on line 39".

$html = '<h2>mpdf test.</h2>';

include("mpdf/mpdf.php");

$mpdf = new mPDF('c','A4','','',32,25,27,25,16,13); 

$mpdf->SetDisplayMode('fullpage');

$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first 
 level of a list

// LOAD a stylesheet
$stylesheet = file_get_contents('mpdfstyletables.css');
$mpdf->WriteHTML($stylesheet,1);    // The parameter 1 tells that this is css/style only and no body/html/text

$mpdf->WriteHTML($html,2);

$mpdf->Output('mpdf.pdf','I');
exit;

Upvotes: 2

Views: 11362

Answers (2)

if ($this->bodyBackgroundColor{0} == 5) { // RGBa Severity: Compile Error

Message: Array and string offset access syntax with curly braces is no longer supported

Filename: src/Mpdf.php

Line Number: 2238

Backtrace:

Upvotes: 0

SaschaM78
SaschaM78

Reputation: 4497

You are directly including mpdf via

include("mpdf/mpdf.php");

which will only include the core file but not any other file mPDF may need in the generation process. The correct way would be to use:

// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';
// Create an instance of the class:
$mpdf = new \Mpdf\Mpdf(); 

This will make sure that required classes will be autoloaded as soon as they are referenced.

For more info, check the "Getting started" chapter on the mPDF web page.

Upvotes: 7

Related Questions