2

我成功地用函数测试了我的代码Zend_Pdf()以便于理解,这是我的代码:

    $pdf = new Zend_Pdf();
    $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
    // set font for page
    // write text to page
        $test = "This is reporting for <br /> hello world: LALALA......";
    $page->setFont($font, 15)
        ->drawText('That which we call a rose,', 72,720)
        ->drawText("$test", 72, 620);
    // add page to document
    $pdf->pages[] = $page;
    $pdf->save("data/reports/" . $_SESSION['User_fonction'] ."-report.pdf");

我的鳕鱼将显示在 pdf 文件中

That which we call a rose

This is reporting for <br /> hello world: LALALA......

我的问题

我如何通过在其中编写标签 html 来解决这个问题,就像标签<br /> 应该知道的那样?请任何曾经了解它的人。任何帮助...

我期待很快看到你的回复。谢谢 。

4

2 回答 2

2

您想要实现的是您拥有 html(即带有标记的文本),并且必须将其转换为 PDF 文件。不幸的是,这不是 Zend_Pdf 的目标。pdf 组件只允许设置纯文本,不允许附加任何标记。

您可以使用名为DomPdfModule的 Zend Framework 2 模块(您使用 zend-framework-2 标记了您的问题,我假设您使用它) 。您使用 Zend Framework 2 视图脚本来呈现结果并使用上述模块将其转换为 PDF 文件。

于 2013-07-17T08:58:05.570 回答
1

Zend_PDF 不会处理 HTML,您应该尝试以下方法:

http://www.tcpdf.org/

http://code.google.com/p/wkhtmltopdf/
于 2013-07-17T08:32:42.947 回答