使用mpdf将内容添加到第二页

时间:2016-01-07 12:32:38

标签: php yii2 mpdf

我正在使用https://github.com/kartik-v/yii2-mpdf在Yii2中创建PDF。我有我的第一页,但我需要添加一个分页符,并确保我在新页面上启动第二条信息。我不确定该怎么做。我试过了:

    public function actionReports()
{
  $data = date('d F Y',time());
  $content = $this->renderPartial('_billing', [
    'model' => $data,
  ]);

  $doc = new Pdf([
    // set to use core fonts only
    'mode' => Pdf::MODE_UTF8,
    // A4 paper format
    'format' => Pdf::FORMAT_A4,
    // portrait orientation
    'orientation' => Pdf::ORIENT_PORTRAIT,
    // stream to browser inline
    'destination' => Pdf::DEST_BROWSER,
    // your html content input
    'content' => $content,
  ]);

  return $doc->render();
}

查看     

use yii\helpers\Html;

?>
<div class="container">
<div class="row">
<div class="col-lg-6 col-lg-offset-3 text-center">
  <?= Html::img(\Yii::getAlias('@web') .  '/images/c.png'); ?>
  <?= Html::img(\Yii::getAlias('@web') .  '/images/s.png', ['width' => 150, 'height' => 55]); ?>
</div>

<div class="col-lg-12  margin-add">
<h4 class="text-center text-gray">Quarterly Billing Summary</h4>

<p><?= $model; ?></p>
....
rest of text
....
<pagebreak/>
...
Tabulated report of billing
...

<pagebreak/>似乎没有呈现第二页?

2 个答案:

答案 0 :(得分:6)

尝试简单地创建包含页面和添加

的视图
"<pagebreak/>" in view where you need this will create page break

更简单的方面是管理两个页面..

这是http://mpdf1.com/manual/index.php?tid=108

您可以使用HTML代码或PHP强制在文档中的任何位置分页:

$mpdf->AddPage();

<pagebreak />

答案 1 :(得分:0)

$invoice_nos = ['0' => $html, '1' => $html, '2' => $html];

$this->mpdf= new mPDF('TH','A4');
$this->mpdf->defaultheaderfontsize=12;
$this->mpdf->defaultheaderfontstyle='B';
$this->mpdf->defaultheaderline=0;
$this->mpdf->setFooter($footer);
$this->mpdf->SetHeader('Bill | | <strong>Pages {PAGENO} of {nb}</strong>');

foreach ($invoice_nos as $key => $invoice_no) {

 $this->mpdf->AddPage();
 $this->mpdf->WriteHTML($html);
}

$this->mpdf->defaultfooterline=0;
$this->mpdf->Output();
$this->mpdf->Output('.date('Y-m-d').'.pdf','F');