当使用Magento时,PDF会在第一页之后切断



使用带有Zend_Pdf的Magento和几个自定义类,允许打印/下载具有特定标题/表规范的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 

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

最新更新