Hi everyone,
I've searched around and can't find an answer to this but I'm sure it's a common problem.
I want to loop round some data and create multiple pdf files. My code (below) runs but I only get one PDF file created.
I have verified that my loop works (by commenting out the do_pdf() function and echoing $filename and $studentname)
Any help and suggestions gratefully received.
Here's a simplified/basic version of my code:
require_once(dirname(__FILE__).'/PDF/html2pdf.class.php');
$invoicedata = $_SESSION['invoicedata'];
foreach ($invoicedata as $id => $invoice)
{
$studentname = $invoice['studentname'];
$template = file_get_contents('invoices/invoice-template.html');
$pdfcontent = str_replace('___NAME___', $studentname, $template);
$filename= 'MyInvoice' . $studentname . '.pdf';
do_pdf($pdfcontent, $filename);
}
function do_pdf($content, $filename)
{
ob_clean();
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->WriteHTML($content);
$html2pdf->Output($filename, 'D');
}