When using Magento, PDF cuts off after first page

381 Views Asked by At

Using Magento with Zend_Pdf and a couple of custom classes that allow for the printing/downloading of PDFs with certain header/table specifications. The problem is that it cuts off after the first page and doesn't create a new page when the items list is more than about 20 items.

This code:

public function getOutput()
{

$this->pages[] = $this->page;

return $this->render();

}

And this code:

$pdf = new PrintPdf();
$pdf->generate($sourceData);
$output = $pdf->getOutput();

echo $output;

Are where I believe the error is happening in. If I change the "return" in the first code to "echo" it will output the correct data to the browser, but when I then try and pass it through the second code, it only puts out one page of data.

Any advice would be appreciated as I have been working on this for about 2 weeks.

UPDATE:

I was told this piece of code:

private function drawLineItems($tableData)
    {
        $this->drawHeading($this->__('Line Items'));

        // Draw table
        $this->decOffset(35);
        $this->colorLine(cBLUE);
        $this->page->setLineWidth(0.5);
        $this->page->drawLine($this->pMargin, $this->yOffset, $this->pWidth - $this->pMargin, $this->yOffset);

        $this->fontSize(FONT_SMALL);
        $this->colorFill(cBLUE);

        $this->decOffset(15);

        $sum = ($this->pMargin + 10);
        for($idx = 0; $idx < sizeof($tableData['heading']); $idx++) {
            $pos = $sum;
            $this->page->drawText($tableData['heading'][$idx], $sum, $this->yOffset);
            $sum += ($tableData['width'][$idx] + 10);
            $tableData['width'][$idx] = $pos;
        }

        $this->decOffset(10);
        $this->page->drawLine($this->pMargin, $this->yOffset, $this->pWidth - $this->pMargin, $this->yOffset);

        $this->fontSize(8);
        $this->colorFill(cLIGHT);
        $this->colorLine(cBORDER);

        foreach($tableData['rows'] as $row) {
            $this->decOffset(15);

            $yOffset = $this->yOffset;

            for($idx = 0; $idx < sizeof($row); $idx++) {
                if ($tableData['heading'][$idx] == 'Description') {
                    $lines = $this->_breakTextToLines($row[$idx], $tableData['width'][$idx + 1] - $tableData['width'][$idx]);
                    foreach ($lines as $line) {
                        $this->page->drawText($line, $tableData['width'][$idx], $yOffset);
                        $yOffset -= 10;
                    }
                } else {
                    $this->page->drawText($row[$idx], $tableData['width'][$idx], $this->yOffset);
                }
            }
            $this->decOffset($this->yOffset - $yOffset);
            $this->page->drawLine($this->pMargin, $this->yOffset, $this->pWidth - $this->pMargin, $this->yOffset);
        }

        $this->decOffset(20);
        $this->fontSize(FONT_NORMAL);
        $this->colorFill(cDARK);
        $this->page->drawText($this->__('Grand Total') . ': ' . $tableData['total'], $this->pWidth - 125, $this->yOffset);
    }

is probably where the problem is as it doesn't form a new page after a certain number of items. My problem now lies in accomplishing this task. Help would still be appreciated.

1

There are 1 best solutions below

0
IUlak On BEST ANSWER

I found that adding this code:

if( $this->yOffset < 25){
                $this->yOffset = $this->pHeight - 25;
                $yOffset = $this->yOffset;
                $this->pages[] = $this->page;
                $this->page = $this->newPage(Zend_Pdf_Page::SIZE_A4);
                $this->fontSize(8);
                $this->colorFill(cLIGHT);
                $this->colorLine(cBORDER);
            }

after

$yOffest = $this->yOffset 

in the third part of the code in the question, fixed the problem!