PHP - Yii2 MPDF 不渲染表格
PHP - Yii2 MPDF not rendering tables
我在 Yii2 中使用 mpdf 扩展来生成 pdf (http://www.yiiframework.com/extension/yii2-mpdf/)
代码如下。
$fileName = 'tst.pdf';
$invoiceHtml = "
<table style = 'height:500px;width:500px' border='1'>
<tr>
<td>Test
</td>
<td>Test2
</td>
</tr>
<tr>
<td>Test
</td>
<td>Test2
</td>
</tr>
<table>
";
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_CORE,
// A4 paper format
'orientation' => Pdf::ORIENT_LANDSCAPE,
// stream to browser inline
'destination' => Pdf::DEST_DOWNLOAD,
// your html content input
'content' => $invoiceHtml,
'filename' =>$fileName,
'cssInline' => ' @page{size: 500mm 200mm}',
// set mPDF properties on the fly
'options' => ['title' => 'Krajee Report Title'],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>['New Horizon Travel And Tours LLC'],
]
]);
return $pdf->render();
代码正在生成空白 pdf 文件。我尝试了其他 HTML 标签和其他标签,纯文本按预期工作。当使用 table 标签时,它正在工作。
寻找这个问题的解决方案
这可能不是您问题的答案。但我之前已经遇到过同样的问题。如果你坚持,你可以使用我的替代方案...
1 - 将您的 Html 代码放入 HTML 文件中......一个单独的文件。
2 - 使用以下代码替换您的代码。
$invoiceHtml = Yii::$app->controller->renderPartial('_yourHtmlFile');
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_CORE,
// A4 paper format
'orientation' => Pdf::ORIENT_LANDSCAPE,
// stream to browser inline
'destination' => Pdf::DEST_DOWNLOAD,
// your html content input
'content' => $invoiceHtml,
'filename' =>$fileName,
'cssInline' => ' @page{size: 500mm 200mm}',
// set mPDF properties on the fly
'options' => ['title' => 'Krajee Report Title'],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>['New Horizon Travel And Tours LLC'],
]
]);
return $pdf->render();
我在 Yii2 中使用 mpdf 扩展来生成 pdf (http://www.yiiframework.com/extension/yii2-mpdf/)
代码如下。
$fileName = 'tst.pdf';
$invoiceHtml = "
<table style = 'height:500px;width:500px' border='1'>
<tr>
<td>Test
</td>
<td>Test2
</td>
</tr>
<tr>
<td>Test
</td>
<td>Test2
</td>
</tr>
<table>
";
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_CORE,
// A4 paper format
'orientation' => Pdf::ORIENT_LANDSCAPE,
// stream to browser inline
'destination' => Pdf::DEST_DOWNLOAD,
// your html content input
'content' => $invoiceHtml,
'filename' =>$fileName,
'cssInline' => ' @page{size: 500mm 200mm}',
// set mPDF properties on the fly
'options' => ['title' => 'Krajee Report Title'],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>['New Horizon Travel And Tours LLC'],
]
]);
return $pdf->render();
代码正在生成空白 pdf 文件。我尝试了其他 HTML 标签和其他标签,纯文本按预期工作。当使用 table 标签时,它正在工作。 寻找这个问题的解决方案
这可能不是您问题的答案。但我之前已经遇到过同样的问题。如果你坚持,你可以使用我的替代方案...
1 - 将您的 Html 代码放入 HTML 文件中......一个单独的文件。 2 - 使用以下代码替换您的代码。
$invoiceHtml = Yii::$app->controller->renderPartial('_yourHtmlFile');
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_CORE,
// A4 paper format
'orientation' => Pdf::ORIENT_LANDSCAPE,
// stream to browser inline
'destination' => Pdf::DEST_DOWNLOAD,
// your html content input
'content' => $invoiceHtml,
'filename' =>$fileName,
'cssInline' => ' @page{size: 500mm 200mm}',
// set mPDF properties on the fly
'options' => ['title' => 'Krajee Report Title'],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>['New Horizon Travel And Tours LLC'],
]
]);
return $pdf->render();