mpdf 不起作用 [致命错误:未找到特征“Mpdf\Strict”]

Mia*_*bar 1 php mpdf

我已经下载了 mpdf 的更新版本并将其与 php 一起使用。它给了我以下错误。

“致命错误:在第 39 行的 E:\xampp\htdocs\PDF\mpdf\Mpdf.php 中未找到特征 'Mpdf\Strict'”。

$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;
Run Code Online (Sandbox Code Playgroud)

Sas*_*M78 6

您直接通过以下方式包含 mpdf

include("mpdf/mpdf.php");
Run Code Online (Sandbox Code Playgroud)

其中仅包含核心文件,而不包含 mPDF 在生成过程中可能需要的任何其他文件。正确的方法是使用:

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

这将确保所需的类在被引用后立即自动加载。

有关详细信息,请查看mPDF 网页上的“入门”一章。