1

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

totals new page

Figure 2

previous page

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;
}
}
4
  • have you customized in "Abstract.php" file?
    – Abdul
    Jan 3, 2017 at 9:17
  • Abdul indeed I have. I have an 150 high footer so in the function in the question I made the lines $this->y - $lineSpacing < 190 and $this->y - $itemsProp['shift'] < 190 Jan 3, 2017 at 9:31
  • If you are trying to default then it working fine or not?
    – Abdul
    Jan 3, 2017 at 9:35
  • Default would take the lines down to 15 thus footer would cover it Jan 3, 2017 at 9:45

1 Answer 1

0

Added following to drawLinesBlock function in abstract.php:

$isTotalsBlock = isset($itemsProp['isTotals']) ? 151 : 205;

Then used this variable here:

 if ($this->y - $lineSpacing < $isTotalsBlock)
 $this->y - $itemsProp['shift'] < $isTotalsBlock

And added following to InsertTotals function (To the linesBlock array):

 'isTotals' => true,

So rather than a static value I am via this catering for a 55 height block i have added. Thus, if the totals block is being drawn then it can go to 151 in the Y-coordinate else 205( 150 footer and 55 block)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.