Hi all hope some one can give me some insight.
OK i am running VirtueMart and trying to send purchase order emails with attached pdfs. Using TCPDF & FPDI to import a template and generate the pdf.
The creation and attaching works fine but..
I am running in to some trouble with trying to use a foreach loop to loop through array and add pages to the pdf. Dont know if i am totally on the wrong path or if i need to make a class or some thing
Here is my code
<?php
require_once( CLASSPATH .'opdf/tcpdf.php');
require_once( CLASSPATH .'opdf/fpdi.php');
//start pdf buffer ->Stops white space from beign send to browser
ob_start();
//Creating PDF
$prodIds = array();
while($dboi->next_record()) {
$my_qty = $dboi->f("product_quantity");
$prodId = $dboi->f("product_id");
$prodPid = $dboi->f("product_parent_id");
$prodName = $dboi->f("product_name");
$attr = trim($dboi->f("product_attribute"));
// Get a list of the parent product ids
$prodIds[$prodPid]['id'] = $prodId;
$prodIds[$prodPid]['name'] = $prodName;
$prodIds[$prodPid]['items'][$attr]['attr'] = $attr;
$prodIds[$prodPid]['items'][$attr]['qty'] = $my_qty;
}
// initiate FPDI
$pdf =& new FPDI('L','mm','A4');
//Loop using parent ids
foreach($prodIds as $prod) {
// no header or footer
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
// add a page
$pdf->AddPage();
// set the sourcefile
$pdf->setSourceFile( CLASSPATH .'opdf/conform.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point origin with a A4 width
$pdf->useTemplate($tplIdx, 0, 0, 297);
// now write some text above the imported page
//Contact
$pdfcontact = $dbbt->f('first_name').' '.$dbbt->f('last_name');
$pdf->SetFont('freesans');
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(23, 21);
$pdf->Write(0, $pdfcontact);
//JobNo
$pdforder = $_SESSION['auth']['username'].' - '. $order_id;
$pdf->SetFont('freesans');
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(88, 21);
$pdf->Write(0, $pdforder);
//DeliveryDate
$pdf->SetFont('freesans');
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(118, 21);
$pdf->Write(0, $del_date);
// Image example
$pdfimage = IMAGEPATH."product/".$dboi->f("product_full_image");
$pdf->Image($pdfimage, 0, 40, 0, 0, '', '', '', false, 72, 'C');
}
//Close and output PDF document
$pdf->Output();
//clean pdf buffer ->Stops white space from beign send to browser
ob_end_clean();
?>
When i have the foreach loop in i get a blank pdf attached.
Any help will be greatly appreciated.