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 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错