Jump to content

[SOLVED] Loop to create multiple pages for TCPDF


Recommended Posts

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
Share on other sites

  • 4 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.