We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

What library to generate PDF?

I guess Phalcon doesn't come with a PDF generating functionality.

If so, what PDF library do you suggest to use with Phalcon?

I just need to generate invoices. Nothing extremely fancy.

Do you have any experience with integration of FPDF or some other library and integrating it with Phalcon?

What type of documents do you want generate? If it simple text and pdf generation do not be used very often you can use FPDF or MPDF (https://www.mpdf1.com/mpdf/index.php).

One of the best way to integrate third-party libraries with Phalcon (and with other php frameworks too) is Composer. You should init the composer in your project and include composer autoloader in Phalcon (for example in app/config/loader.php - if you use default phalcon app skelet):

/**
 * Require Composer autoloader
 */
require_once __DIR__ . '/../../vendor/autoload.php';

For one of my project I use Apache FOP - https://xmlgraphics.apache.org/fop/ (written in Java). I generate advanced financial reports and invoices with customizable templates. I modify default servlet delivered with FOP library and now it works as an internal webservice with very simple REST API. There is not any efficient library written in PHP (they are slow, require large amount of RAM and quite high CPU usage in comparison to libraries written in Java, Python or Ruby).



37.0k

Thanks, I will probably try to integrate mpdf to Phalcon. My invoices are like page long with a few text , logo etc. nothing fancy, so hopefully mpdf can do the job.

We use wkhtmltopdf after trying out dompdf, fpdf, mpdf, and several js solutions.

The main reasons for switching for us were:

  1. Speed of rendering (dompdf would take 2-4 seconds per 4-5 page pdf on large boxes. Wkhtml cuts that down to 500-750ms
  2. Quality of rendering. Wkhtml uses webkit and renders javascript graphing libraries really well. Other solutions struggled rendering documents with heavy dom
  3. Speed of development. Other solutions require more massaging of the output. Wkhtml renders the pdf as the print layout of the page allowing for using existing responsive styles

lib https://wkhtmltopdf.org/ php wrapper https://github.com/mikehaertl/phpwkhtmltopdf

I've found TCPDF to be the best. Complete documentation and it's quite robust. Like any PDF library though, it does have a bit of a learning curve. Fortunately, there are tons of examples.

edited Mar '15

I'm one of the developers so I'm a bit bias, but you might also consider Doc Raptor. It's a commercial-grade HTML-to-PDF API that is super fast, scalable and relatively inexpensive. It also supports XLS files. I'll look into adding some sort of Phalcon integration.

You have used TCPDF inside phalcon? How you achieve that if you did... Thanks

I've found TCPDF to be the best. Complete documentation and it's quite robust. Like any PDF library though, it does have a bit of a learning curve. Fortunately, there are tons of examples.



43.9k
edited Dec '16

Awseome tool. It saved my day !!!

We use wkhtmltopdf after trying out dompdf, fpdf, mpdf, and several js solutions.

The main reasons for switching for us were:

  1. Speed of rendering (dompdf would take 2-4 seconds per 4-5 page pdf on large boxes. Wkhtml cuts that down to 500-750ms
  2. Quality of rendering. Wkhtml uses webkit and renders javascript graphing libraries really well. Other solutions struggled rendering documents with heavy dom
  3. Speed of development. Other solutions require more massaging of the output. Wkhtml renders the pdf as the print layout of the page allowing for using existing responsive styles

lib https://wkhtmltopdf.org/ php wrapper https://github.com/mikehaertl/phpwkhtmltopdf