<div class='postHeader'>
<div>{post.title}</div>
<div>{post.author}</div>
</div>
以上代码用于使用YII框架生成PDF。
答案 0 :(得分:0)
前两行将创建css $pdf_style
和html文件$pdf_part
,PDF将写入此文件。
在WriteHTML
函数中包含这两个变量。
$pdf_style = \Yii::$app->view->renderFile(PROTECTEDPATH . 'common/views/contract/style.css', $data);
$pdf_part = \Yii::$app->view->renderFile(PROTECTEDPATH . 'common/views/contract/file.tpl', $data);
$mpdf = new \mPDF('utf-8','A4');
$mpdf->autoScriptToLang = true;
$mpdf->baseScript = 1; // Use values in classes/ucdn.php 1 = LATIN
$mpdf->autoVietnamese = true;
$mpdf->autoArabic = true;
$mpdf->autoLangToFont = true;
$mpdf->SetMargins(null,null,40);
$mpdf->SetDisplayMode('fullpage');
$mpdf->SetHTMLHeader('<div style="text-align:right"><img src="'. DOCROOT .'images/logo_contract.png" height="68" /></div>');
$mpdf->setFooter(' | www.facebook.com | {PAGENO}');
$mpdf->WriteHTML($pdf_style.'<div class="wrapper">'.$pdf_part.'</div>');
$mpdf->Output('Contract-'.date("iYsmd"), $action, $dest);