PDF gen working better. Need to fix up product description Cell height better

This commit is contained in:
Karl Cordes 2009-11-19 14:57:55 +11:00
parent 40f30519ab
commit 5c75f512d7
2 changed files with 127 additions and 37 deletions

101
vendors/xtcpdf.php vendored
View file

@ -164,7 +164,7 @@ class XTCPDF extends TCPDF {
$this->SetFontSize(10); $this->SetFontSize(10);
$lineHeight = 5; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs $lineHeight = 5.8; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs
@ -184,6 +184,50 @@ class XTCPDF extends TCPDF {
echo "Product Page height is: ".$this->getPageHeight(); echo "Product Page height is: ".$this->getPageHeight();
$availableHeight = 253; //Figured out experimentally. Approx 253mm of space left for the actual table data after the header rows.
echo "Remaining space on the page is: $availableHeight <br>";
$pagesRequired = 1;
$theseProductsHeight = 0;
$remainingHeight = $availableHeight;
$pageProducts = array(); //Array in the form $pageProducts[$pageNumber] = NUMBER_OF_ITEMS_ON_THIS_PAGE
//Can see already the final summary total thing is going to be a bit of a bitch to do.
foreach ($products as $product) {
$fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
$linesNeeded = $this->getNumLines($fullDesc, $descColwidth);
$mmNeeded = $linesNeeded*$lineHeight;
if($remainingHeight - $mmNeeded <= 0) {
$pagesRequired++;
$remainingHeight = $availableHeight; //Start checking the next page;
$remainingHeight -= $mmNeeded;
$pageProducts[$pagesRequired][] = $product;
}
else {
$remainingHeight -= $mmNeeded;
$pageProducts[$pagesRequired][] = $product;
}
}
print_r($pageProducts[1]);
echo "We need to make $pagesRequired product pages<br>";
for($i=1; $i<=$pagesRequired; $i++) {
$this->AddPage();
//Draw Header Rows //Draw Header Rows
@ -214,10 +258,55 @@ class XTCPDF extends TCPDF {
$this->MultiCell($totalPricColwidth, $heightNeeded, $currency, 1, "C", 1, 1); $this->MultiCell($totalPricColwidth, $heightNeeded, $currency, 1, "C", 1, 1);
echo "POOOO";
foreach ($products as $product) {
//Start Printing Product cells, until we run out of room. Then continue on the next page
foreach($pageProducts[$i] as $product) {
$fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
$linesNeeded = $this->getNumLines($fullDesc, $descColwidth);
// echo "<br>";
//echo $product[$docType]['title']." needs $linesNeeded so approx ".$linesNeeded*$lineHeight." mm <br>";
$mmNeeded = $linesNeeded*$lineHeight;
$this->MultiCell($itemColwidth, $mmNeeded, number_format($product[$docType]['item_number'], 1, '.', ''), 1, "C", 0, 0);
$this->MultiCell($qtyColwidth, $mmNeeded, $product[$docType]['quantity'], 1, "C", 0, 0);
$this->MultiCell($descColwidth, $mmNeeded, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true);
$this->MultiCell($unitpriceColwidth, $mmNeeded, "$1000", 1, "C", 0, 0);
$this->MultiCell($totalPricColwidth, $mmNeeded, "$2000", 1, "C", 0, 1);
}
$this->AliasNbPages();
$this->lastPage();
}
// echo "Y is currently ".$this->GetY();
// $availableHeight = $this->getPageHeight() - $this->GetY() - 10;
/* foreach ($products as $product) {
//Need to use the getNumLines method to figure out how big to make the cells before the description cell //Need to use the getNumLines method to figure out how big to make the cells before the description cell
$fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description']; $fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
@ -231,9 +320,6 @@ class XTCPDF extends TCPDF {
$this->MultiCell($itemColwidth, $mmNeeded, number_format($product[$docType]['item_number'], 1, '.', ''), 1, "C", 0, 0); $this->MultiCell($itemColwidth, $mmNeeded, number_format($product[$docType]['item_number'], 1, '.', ''), 1, "C", 0, 0);
$this->MultiCell($qtyColwidth, $mmNeeded, $product[$docType]['quantity'], 1, "C", 0, 0); $this->MultiCell($qtyColwidth, $mmNeeded, $product[$docType]['quantity'], 1, "C", 0, 0);
$this->MultiCell($descColwidth, $mmNeeded, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true); $this->MultiCell($descColwidth, $mmNeeded, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true);
$this->MultiCell($unitpriceColwidth, $mmNeeded, "$1000", 1, "C", 0, 0); $this->MultiCell($unitpriceColwidth, $mmNeeded, "$1000", 1, "C", 0, 0);
@ -243,12 +329,17 @@ class XTCPDF extends TCPDF {
} }
* */
} }
// function productPageHTML() {
// }

View file

@ -85,9 +85,9 @@ foreach ($quote['QuotePage'] as $page) {
} }
$tcpdf->AddPage();
print_r($products);
//print_r($products);
$principle_name = strtoupper($enquiry['Principle']['name']); $principle_name = strtoupper($enquiry['Principle']['name']);
@ -95,8 +95,7 @@ $tcpdf->productPage($principle_name, $quote['Currency']['iso4217'], $products, '
$tcpdf->AliasNbPages();
$tcpdf->lastPage();
$output_dir = '/Users/karlcordes/Sites/quotenik/app/webroot/pdf/'; $output_dir = '/Users/karlcordes/Sites/quotenik/app/webroot/pdf/';