Zend PDF问题

时间:2011-09-26 18:13:43

标签: php oop zend-framework

我为自己制作了这个简单的类,用于按行将文本绘制到特定页面中。这是它的外观:

class pdf {
    public $path;
    private $pdf;
    private $page;
    private $font;
    private $visibleLineYValue = 600;


    public function __construct() {
        require_once './Zend/Pdf.php';
    }

    public function loader($page) {
        $this->pdf = Zend_Pdf::load($this->path);

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

    public function fontSetter($size) {
        $this->font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES_BOLD);
        $this->page->setFont($this->font, $size);
    }

    public function drawVisibleLine($content) {
        $page->drawText($content, 20, $this->visibleLineYValue);
        $this->visibleLineYValue - 40;
    }

    public function saver() {
        $pdf->save('something.pdf');
    }
}

问题是,当我打电话给这个班级时......就像那样:

$pdf = new pdf();
    $pdf->path = 'PJ Pracovnepravni.pdf';
    $pdf->loader(1);
    $pdf->fontSetter(13);
    $pdf->drawVisibleLine('Lorem');
    $pdf->drawVisibleLine('Ipsum');
    $pdf->drawVisibleLine('Dolor');
    $pdf->saver();

......它写道:

Notice: Undefined variable: page in E:\!localhost\woltersKluwer\classes\pdf.php on line 31

Fatal error: Call to a member function drawText() on a non-object in E:\!localhost\woltersKluwer\classes\pdf.php on line 31

如果我正确理解它,则意味着私有变量$ page未定义,但如果我看到它是定义的那么好。

提前致谢

1 个答案:

答案 0 :(得分:1)

你在最后两种方法中错过了$this

public function drawVisibleLine($content) {
    $this->page->drawText($content, 20, $this->visibleLineYValue);
    $this->visibleLineYValue - 40;
}

public function saver() {
    $this->pdf->save('something.pdf');
}

如果没有这个,解释器会查找本地变量$page