Is possible convert HTML into pdf using Zend_Pdf?

断了今生、忘了曾经 提交于 2019-12-03 07:01:28

问题


Is possible convert directly HTML into a pdf file using Zend_Pdf?, if so, How can I do that?


回答1:


Zend_PDF isn't able to generate PDF based on HTML. But you can render view and use other library for convert it to PDF. I've done such thing with TCPDF. Little code snippet below:

    //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');



回答2:


tcpdf is a little limited when it comes to html, wkhtmltopdf uses webkit




回答3:


i've used dompdf https://github.com/dompdf/dompdf its pretty easy and straight forward. it even reads/formats css.




回答4:


Check out MPDF . The ultimate one. Create your html with inline css, store it in one php variable and echo to pdf file. you are done!!!



来源:https://stackoverflow.com/questions/5183238/is-possible-convert-html-into-pdf-using-zend-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!