开发者

Zend PDF problem

I made for myself this simple class for drawing text by lines into specific pages. This is how it looks:

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

The problem is, taht when I call this class... like that:

$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();

...it writes this:

Notice: Undefined variable: page in E:\!localhost\woltersKluwer\classes\pdf.php on line 3开发者_如何学JAVA1

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

If I correctly understand it, it means that private variable $page is not define, but if I see good it is define.

Thanks in advance for answer


You're missing a $this in the last two methods:

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

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

Without this, the interpreter looks for a local variable $page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜