Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is possible convert HTML into pdf using Zend_Pdf?

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

like image 465
texai Avatar asked Mar 03 '11 16:03

texai


2 Answers

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');
like image 89
Radek Benkel Avatar answered Nov 15 '22 21:11

Radek Benkel


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

like image 26
Brendon-Van-Heyzen Avatar answered Nov 15 '22 22:11

Brendon-Van-Heyzen