Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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) -

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.