Hi guys the totals block in my invoice pdf keeps going to a new page, even though there is room on the previous page (Figure 1 is totals block on new page and Figure2 is previous page):
Figure 1
Figure 2
Code in Abstract.php I believe prints out the totals block:
public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSettings = array())
{
foreach ($draw as $itemsProp) {
if (!isset($itemsProp['lines']) || !is_array($itemsProp['lines'])) {
Mage::throwException(Mage::helper('sales')->__('Invalid draw line data. Please define "lines" array.'));
}
$lines = $itemsProp['lines'];
$height = isset($itemsProp['height']) ? $itemsProp['height'] : 10;
if (empty($itemsProp['shift'])) {
$shift = 0;
foreach ($lines as $line) {
$maxHeight = 0;
foreach ($line as $column) {
$lineSpacing = !empty($column['height']) ? $column['height'] : $height;
if (!is_array($column['text'])) {
$column['text'] = array($column['text']);
}
$top = 0;
foreach ($column['text'] as $part) {
$top += $lineSpacing;
}
$maxHeight = $top > $maxHeight ? $top : $maxHeight;
}
$shift += $maxHeight;
}
$itemsProp['shift'] = $shift;
}
if ($this->y - $itemsProp['shift'] < 190) {
$this->footer($page);
$page = $this->newPage($pageSettings);
}
foreach ($lines as $line) {
$maxHeight = 0;
foreach ($line as $column) {
$fontSize = empty($column['font_size']) ? 10 : $column['font_size'];
if (!empty($column['font_file'])) {
$font = Zend_Pdf_Font::fontWithPath($column['font_file']);
$page->setFont($font, $fontSize);
} else {
$fontStyle = empty($column['font']) ? 'regular' : $column['font'];
switch ($fontStyle) {
case 'bold':
$font = $this->_setFontBold($page, $fontSize);
break;
case 'italic':
$font = $this->_setFontItalic($page, $fontSize);
break;
default:
$font = $this->_setFontRegular($page, $fontSize);
break;
}
}
if (!is_array($column['text'])) {
$column['text'] = array($column['text']);
}
$lineSpacing = !empty($column['height']) ? $column['height'] : $height;
$top = 0;
foreach ($column['text'] as $part) {
if ($this->y - $lineSpacing < 190) {
$page = $this->newPage($pageSettings);
}
$feed = $column['feed'];
$textAlign = empty($column['align']) ? 'left' : $column['align'];
$width = empty($column['width']) ? 0 : $column['width'];
switch ($textAlign) {
case 'right':
if ($width) {
$feed = $this->getAlignRight($part, $feed, $width, $font, $fontSize);
}
else {
$feed = $feed - $this->widthForStringUsingFontSize($part, $font, $fontSize);
}
break;
case 'center':
if ($width) {
$feed = $this->getAlignCenter($part, $feed, $width, $font, $fontSize);
}
break;
}
$page->drawText($part, $feed, $this->y-$top, 'UTF-8');
$top += $lineSpacing;
}
$maxHeight = $top > $maxHeight ? $top : $maxHeight;
}
$this->y -= $maxHeight;
}
}
return $page;
}
}