We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Generating PDF file wih Phalcon


I saw this topic


but, I need more informations for how to generate pdf with phalcon.

how should I proceed?

for sample, in the action "pdf_report", what should I put?

where can I get examples?

sorry for my english



You will first need to have the mpdf library available to you (usually by composer) - https://github.com/mpdf/mpdf

In an action (that you will choose) say pdf_reportAction you gather all the data you need and inject it in a view. That will return a string which should be well formed XML. You pass that string to the mpdf library and your file is there :)

Something like this:

public function pdf_reportAction()

    // Get all the data from the database
    $data = Posts::find();   

    // Get the view data
    $html = $this->view->getRender('reports', 'pdf_report', $data);

    $pdf = new mPDF();
    $pdf->WriteHTML($html, 2);
    // .....

Your view will get the $data and do something with it like any view that shows data on screen. You can present things in a table or whatever you like.