【发布时间】:2014-10-09 16:05:20
【问题描述】:
我在 CodeIgniter 中使用 mpdf 库来生成 PDF 文件。
我希望从单个 for 循环生成 4 个文件。但它只生成一个文件。
下面是代码
$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);
即使我删除了这些未设置的方法,不仅如此,我还通过在代码上应用 cmets 打印了这些数据。循环内的数据很好,但不会生成多个文件。它只生成单个文件。
有什么建议吗?
【问题讨论】:
-
嗨,你不应该循环加载库
$this->load->library('mpdf56/mpdf');。为所有 pdf 操作加载一次。 -
我也试过了。但什么也没发生。
-
好的,当我想从循环内通过电子邮件发送多个 PDF 文件作为附件时,我遇到了同样的问题。第一个很好,所有其他附件或与第一个文件相同。这个问题有什么进展吗??
标签: php codeigniter pdf mpdf