pdfを生成するためにYii2でmpdf拡張機能を使用しています(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タグや他のタグを試しましたが、プレーンテキストは期待どおりに機能しています。テーブルタグを使用すると、機能します。この問題の解決策を探しています
これはあなたの質問に対する答えではないかもしれません。しかし、私は以前に同じ問題にすでに直面しています。あなたが主張するなら、あなたは私の代わりを使うかもしれません...
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();
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加