在php中循环生成多个PDF文件

时间:2012-08-21 08:23:10

标签: php

我想使用循环创建多个pdf文件。 我将代码如下所示,但只生成一个文件,所有数据都只写入该文件。如何生成多个文件。

我的代码是..

for($i=0;$i<4;$i++)
{

$pli_ids=explode(",",$string);
foreach($pli_ids as $id)
{

    $data[]=array('inv_no'=>$inv_obj->invoice_number,'Work_order'=>'gandalf','data_type'=>$pli_obj->data_type_c_pl_c,'subscription'=>'subs1','hs_code'=>'hs1');
}
require_once ('include/pdf/class.ezpdf.php');
$pdf =& new Cezpdf();   
$pdf->selectFont('include/fonts/Helvetica.afm');

$pdf->ezSetY(750);
$pdf->ezText(date('d:M:Y'),14); $pdf->ezSetY(720);
$pdf->ezText('To,',14); $pdf->ezSetY(690);
$pdf->ezText('Mr. Kumar {contact Name}',14); $pdf->ezText('Kunal And Company Ltd {Account Name}',14);
$pdf->ezText('No 6, IInd Floor Marine Drive {contact shipping address}',14);$pdf->ezSetY(610);
$pdf->ezText('Mumbai, Pin: 560079',14); $pdf->ezText('Maharashtra',14);$pdf->ezText('Mob.:9977200030',14);
$pdf->ezSetY(550);
$pdf->ezText(' <c:uline>Sub.: Your order of Export Import News </c:uline> ',15);
$pdf->ezSetY(520);  
$pdf->ezText('Dear Mr. Kumar, {Customer Name}',14);
$pdf->ezSetY(490);
$pdf->ezText('Greetings for the day!.',14); $pdf->ezSetY(460);
$pdf->ezText('Thanks for being a valuable customer of Infodrive India,we have enclosed the data as follows.');
$pdf->ezSetY(430);  
$pdf->ezTable($data,array('inv_no'=>'Inv No.','Work_order'=>'Work Order non','data_type'=>'Data Type','subscription'=>'subscription','hs_code'=>'HS Code'),
    '',
    array('showHeadings'=>2,'shaded'=>1,'xPos'=>'right','xOrientation'=>'left','width'=>400));
$filename = "pdf_".$i;
$pdf->ezStream(array("Content-Disposition"=>$filename));

}

1 个答案:

答案 0 :(得分:0)

您正在使用ezStream()将pdf发送到浏览器。您只能以这种方式发送一个文件。