bobdabuilder Posted June 30, 2009 Share Posted June 30, 2009 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. Link to comment https://forums.phpfreaks.com/topic/164171-solved-loop-to-create-multiple-pages-for-tcpdf/ Share on other sites More sharing options...
bobdabuilder Posted July 1, 2009 Author Share Posted July 1, 2009 Ok fixed it was a rookie error!! Link to comment https://forums.phpfreaks.com/topic/164171-solved-loop-to-create-multiple-pages-for-tcpdf/#findComment-867424 Share on other sites More sharing options...
Freddyfudder Posted July 29, 2009 Share Posted July 29, 2009 would you mind sharing what the error was? Link to comment https://forums.phpfreaks.com/topic/164171-solved-loop-to-create-multiple-pages-for-tcpdf/#findComment-885942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.