是否可以使用 Zend_Pdf 将HTML直接转换为 pdf 文件?如果可以,我该怎么做?
问问题
27114 次
4 回答
12
Zend_PDF
无法生成基于 HTML 的 PDF。但是您可以渲染视图并使用其他库将其转换为 PDF。我用TCPDF做过这样的事情。下面的小代码片段:
//SomeController.php
$this->_helper->layout->disableLayout();
//set content for view here
// create new PDF document
require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
//whole TCPDF's settings goes here
$htmlcontent = $this->view->render('recipe/topdf.phtml');
// output the HTML content
$pdf->writeHTML($htmlcontent, true, 0, true, 0);
$pdf->lastPage();
$pdf->Output("pdf-name.pdf", 'D');
于 2011-03-03T18:30:28.423 回答
2
tcpdf在html方面有点局限,wkhtmltopdf使用webkit
于 2011-03-03T18:54:08.170 回答
2
查看MPDF。最后一个。使用内联 css 创建您的 html,将其存储在一个 php 变量中并回显到 pdf 文件。你完成了!
于 2013-05-15T07:17:24.120 回答
1
我使用过 dompdf https://github.com/dompdf/dompdf,它非常简单直接。它甚至可以读取/格式化 css。
于 2011-03-05T09:07:57.207 回答