有可能转换 直 使用Zend_Pdf?将HTML转换为pdf文件,如果是这样,我该怎么做?
有可能转换 直 使用Zend_Pdf?将HTML转换为pdf文件,如果是这样,我该怎么做?
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');
tcpdf在html方面有点受限, wkhtmltopdf 使用webkit
我用过dompdf https://github.com/dompdf/dompdf 它非常简单直接。它甚至可以读/格式化CSS。
查看 MPDF 。最终的一个。使用内联css创建html,将其存储在一个php变量中并回显到pdf文件。你完成了!!!