Generating PDF file in Phalcon framework

I am using phalcon framework, and i need to generate pdf file. I was thinking to use mpdf library, i serached online and i didn't find how to use mpdf in phalcon for generating pdf files. Please, I need some example of how can i do this , in easiest way. I worked with mpdf in codeigniter, and here is my function example:

    public function createPdf(){
    $userId = $this->input->post('bbb');

    $this->load->model('osoba');
    $this->load->library('pdf');
    $rez['rez'] = $this->osoba->getUsers($userId);
    $html = $this->load->view('pdf_report', $rez, true);
    $pdf = $this->pdf->load();
    $pdf->WriteHTML($html, 2);
    $br = rand(0,100000);
    $ispis = "Pobjeda Rudet-Izvjestaj-".$br;
    $pdf->Output($ispis, 'I');
}

I need to achieve this in Phalcon, please I neeed your help. Thanks in advance.



83.4k

Try this:

public function createPdf()
{
    $this->view->disable();

    $userId = $this->request->getPost('bbb');   

    $rez['rez'] = Users::findFirstById($userId)
    $html = $this->view->getRender('reports', 'pdf_report', $rez);

    $pdf = new mPDF();

    $pdf->WriteHTML($html, 2);
    $br = rand(0, 100000);
    $ispis = "Pobjeda Rudet-Izvjestaj-".$br;

    $pdf->Output($ispis, "I");
}
edited Oct '15

And how do I use mPDF the Phalcon? Because from what I researched, the mPDF does not work with namespace.

True, mPDF live in the global namespace... but it has it's own loader in include("../mpdf.php");, so there's no need to do anything special in Phalcon. Just include that file and define any globals according to the mPDF docs. There shouldn't be any collisions.