You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Yii2中使用Mpdf生成PDF报Undefined index: l错误求助

Yii2中Mpdf生成PDF报错:Undefined index: l

HTML内容在网页端显示正常,但在Yii2 PHP环境下使用Mpdf生成PDF时出现错误。以下是两种实现代码:

Code 1

$content = 'HTML CODE';
$pdf = new Mpdf();
$stylesheet = file_get_contents('../styles.css'); // 外部CSS文件
$pdf->WriteHTML($stylesheet,1);
$pdf->WriteHTML($content);

try{
    return $pdf->output();
} catch (\Exception $e) {
    throw new Exception($e, 500);
}

Code 2

$content = 'HTML CODE';
$pdf = new kartik\mpdf\Pdf([
    'mode' => Pdf::MODE_CORE,
    'format' => Pdf::FORMAT_A4,
    'orientation' => Pdf::ORIENT_PORTRAIT,
    'content' => $content,
    'filename' => 'PdfFile',
    'cssFile' => '../styles.css',
]);
try{
    return $pdf->render();
}  catch (\Exception $e) {
    throw new Exception($e, 500);
}

错误信息

"name": "PHP Notice",
"message": "Undefined index: l",
"code": 8,
"type": "yii\base\ErrorException",
"file": "..vendor\mpdf\mpdf\src\Mpdf.php",
"line": 20167,

已确认HTML标签闭合正常,PDF生成前的HTML内容显示正常。


内容的提问来源于stack exchange,提问作者Krishna Ramchandani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 13:00:00