dt250827 2014-05-19 16:26
浏览 191
已采纳

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;
    }
  • 写回答

1条回答 默认 最新

  • doucao8982 2014-05-19 22:32
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?