使用 Magento 时,PDF 在第一页后被截断

When using Magento, PDF cuts off after first page

将 Magento 与 Zend_Pdf 和一些自定义 类 结合使用,这些自定义 类 允许 printing/downloading 具有特定 header/table 规格的 PDF。问题是它在第一页之后中断,并且当项目列表超过 20 个项目时不会创建新页面。

此代码:

public function getOutput()
{

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

return $this->render();

}

还有这段代码:

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

echo $output;

我认为错误发生的地方。如果我将第一个代码中的 "return" 更改为 "echo" 它将向浏览器输出正确的数据,但是当我尝试通过第二个代码,它只输出一页数据。

任何建议将不胜感激,因为我已经为此工作了大约 2 周。

更新:

有人告诉我这段代码:

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);
    }

可能是问题所在,因为它在一定数量的项目后没有形成新页面。我现在的问题在于完成这个任务。仍将不胜感激。

我发现添加这段代码:

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);
            }

之后
$yOffest = $this->yOffset 

在问题的第三部分代码中,修复了问题!