MPDF:多页中的独立信息

I actually use MPDF in order to show my HTML code on a PDF. The problem that I have a lot of payroll employees , and I want to make each payroll on a page. This code works well.

        $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;

But the problem is that my payrolls is shown successively in the same page. Now I want to make each payroll on an independant page . I have to use a foreach , but I don't know where is the error , because it's shown to me the same result :

        $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;
    }

You need to :

  • Change your partial file to generate the HTML for only one payroll (fiche).
  • Update your code

Example

$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;

Hope it helps