使用 Zend (fontWithName) 创建 PDF 时出错

Error creating PDF with Zend (fontWithName)

我正在尝试使用 Zend 生成 PDF 文件,但在尝试设置字体时总是出现错误。

这是我的代码:

$pdf = new Zend_Pdf();

    $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    $font = new Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);

    $page->setFont($font,24)
         ->drawText("Hello world!",72,720);

    $pdf->$page;
    $pdf->save("example.pdf");

这是错误:

 Parse error: syntax error, unexpected 'fontWithName' (T_STRING), expecting variable (T_VARIABLE) or '$' in /Users/pawel/Sites/Zend/application/modules/default/controllers/IndexController.php on line 83

我想你可以删除字体声明的 new:

$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);

$style = new Zend_Pdf_Style();
$style->setFont($font, 24);
$page->setStyle($style);

fontWithName 是静态函数,Zend_Pdf_Font 是抽象函数 class.

例如参见documentation

还有一个问题:
替换

$pdf->$page;

来自

$pdf->pages[] = $page;