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
相关产品推荐
相关产品推荐

