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

时间:2015-08-07 15:09:33

标签: php magento pdf zend-pdf

使用Magento和Zend_Pdf以及一些允许打印/下载具有特定标题/表格规范的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);
    }

可能是问题所在,因为在一定数量的项目之后它不会形成新页面。我现在的问题在于完成这项任务。帮助仍然会受到赞赏。

1 个答案:

答案 0 :(得分:0)

我发现添加此代码:

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 

在问题代码的第三部分,解决了问题!

相关问题