tex*_*xai 11 html pdf zend-framework zend-pdf
是否可以使用Zend_Pdf 将HTML 直接转换为pdf文件?如果是这样,我该怎么做?
Rad*_*kel 11
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');
Run Code Online (Sandbox Code Playgroud)