MPDF:多页中的独立信息

use*_*203 2 php zend-framework

我实际上使用MPDF来在PDF上显示我的HTML代码.我有很多工资单员工的问题,我想在页面上制作每个工资单.这段代码效果很好.

        $html  = $this->view->partial('fiche/telechargerfiche.phtml',
            array('fichep' => $recuperationFiche));

    $mpdf=new mPDF();
    foreach ($recuperationFiche as $fiche) {

    $mpdf->SetDisplayMode('fullpage');
    $mpdf->WriteHTML($html);
    $mpdf->SetHTMLFooter("<div style='text-align: center'><img src='pieddepage.jpg' /></div>") ;
    $mpdf->Output();
    exit;
Run Code Online (Sandbox Code Playgroud)

但问题是我的工资单连续显示在同一页面中.现在我想在一个独立的页面上创建每个工资单.我必须使用foreach,但我不知道错误在哪里,因为它向我显示了相同的结果:

        $html  = $this->view->partial('fiche/telechargerfiche.phtml',
            array('fichep' => $recuperationFiche));

    $mpdf=new mPDF();
    foreach ($recuperationFiche as $fiche) {

    $mpdf->SetDisplayMode('fullpage');
    $mpdf->WriteHTML($html);
    $mpdf->SetHTMLFooter("<div style='text-align: center'><img src='pieddepage.jpg' /></div>") ;
    $mpdf->Output();
    exit;
    }
Run Code Online (Sandbox Code Playgroud)

php*_*dev 6

你需要 :

  • 更改部分文件以仅为一个工资单(fiche)生成HTML.
  • 更新您的代码

$mpdf = new mPDF(); 
$mpdf->SetDisplayMode('fullpage'); 

foreach ($recuperationFiche as $i => $fiche) {

    if($i) { //If not the first payroll then add a new page
        $mpdf->AddPage();
    }
    $html = $this->view->partial(
        'fiche/telechargerfiche.phtml', 
        array('fichep' => $fiche)
    );
    $mpdf->WriteHTML($html);

}

$mpdf->SetHTMLFooter( "" ); 
$mpdf->Output(); 
exit;
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你