Reputation: 499
I don't know why its not working. I've used while loop to generate multiple pdfs with ezpdf class, and only 1 pdf is creating. I also tried 'for loop' but is still the same . What should i do to achieve more than one pdf?
include ('class.ezpdf.php');
$limit = 1;
while($limit < 5){
$colw = array( 80 , 40, 220, 80, 40 );//column widths
$rows = array(
array('company','size','desc','cost','instock'),
array("WD", "80GB","WD800AAJS SATA2 7200rpm 8mb" ,"$36.90","Y"),
);
//x is 0-600, y is 0-780 (origin is at bottom left corner)
$pdf =& new Cezpdf('LETTER');
$total=0;
$curr_x=80;
$curr_y=600;
foreach($rows as $r)
{
$xoffset = $curr_x;
foreach($r as $i=>$data)
{
$pdf->setColor(0/255,0/255,0/255);
$pdf->addText( $xoffset, $curr_y , 10, $data );
$xoffset+=$colw[$i];
}
$curr_y-=20;
}
define('MY_FILENAME', 'testDoc'.$limit.'.pdf');
$pdfcode = $pdf->ezOutput();
$fp = fopen(MY_FILENAME, 'wb');
fwrite($fp, $pdfcode);
fclose($fp);
}
Upvotes: 0
Views: 794
Reputation: 77
Maybe I think your problem occurs because you try to set a constant value with define() in a loop. I tested it and the define-variable (MY_FILENAME) had always the same value inside a loop. It seems that PHP doesn't set defined variables again.
Your solution woul'd be to replace your define variable (MY_FILENAME) with a regular variable like this...
for ($i = 0; $i < 10; $i++)
{
$myPDFFile = "PDF" . $i . ".pdf";
$pdf = new Cezpdf('A4'); // create CezPDF-object
// write content to PDF-file
$pdfCode = $pdf->output(); // content of PDF to variable
$file = fopen($myPDFFile, "wb");
fwrite($file, $pdfCode);
fclose($file);
}
instead of
for ($i = 0; $i < 10; $i++)
{
define(MY_FILENAME, "testDoc" . $i . ".pdf");
...
}
I hope this woul'd work for you.
Upvotes: 1