dongta5621 2014-10-09 16:05
浏览 60

在CodeIgniter中使用单个for循环生成多个PDF文件

I am using mpdf library in CodeIgniter for generating PDF files.

I want 4 files to be generated from single for loop. But it is only generating one file.

Below is the code

$dataArr = $notificationReports['data'];
        $chunkReport = count($dataArr);

        if($chunkReport > 1000){
            $chunkSize = ($chunkReport / 4);
            $chunks = array_chunk($dataArr,$chunkSize);
            for($i = 0; $i <= 3; $i++){

                $this->load->library('mpdf56/mpdf');
                $paper='A4';
                $notificationReports['data'] = $chunks[$i];
                $notificationReports['heading'] = array(
                                    'S. NO',
                                    'SENT DATE',
                                    'SENT BY',
                                    'SENT TO',
                                    'MESSAGE',
                                    'SMS'
                                );


                $mpdf=new mPDF('utf-8',$paper,'','','','','',10,'',3,'L');
                $html = $this->load->view('reports/pdf_view_report',$notificationReports,true);
                $mpdf->WriteHTML($html);
                $mpdf->Output($title.".pdf",'D');
                unset($mpdf);
                unset($notificationReports);
                unset($html);

Even I have removed these unset methods, and not only this, I have printed this data by applying comments on the code. Data inside the loop is fine, but only not generating multiple files. It is only generating single file.

Any suggestions?

  • 写回答

2条回答 默认 最新

  • dtrj21373 2014-10-09 18:41
    关注

    Have you tried this:

    $mpdf->Output($title.$i.".pdf",'D');
    

    Instead of

    $mpdf->Output($title.".pdf",'D');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化