Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create PDF file taking huge data from MySQL using PHP

I want to make a PDF file which will contain huge data such as 12 months data. Each month contain 500 rows from MySQL table. I have tried with FPDF but it takes too much time that is unacceptable. If there is any other better PHP library or class to make it easily and not make the system busy?

If there is any script which will take 12 months data one month by one month and write it to PDF one by one and finally create the PDF file?

like image 973
Nantu Avatar asked Dec 24 '12 08:12

Nantu


2 Answers

I routinely create very large PDFs from PHP using (usually) the same method. First I create a web page version of the document and output that to a file. Then I run the file through wkhtmltopdf. I've had consistently more success with this method than any other. The HTML should be quick to generate and wkhtmltopdf is surprisingly fast and efficient. Plus you can use CSS3 techniques for elaborate formatting.

For extremely large PDFs I've also generated smaller ones and then merged them with pdfmeld. This also gives you the option of adding bookmarks.

like image 200
Matt S Avatar answered Nov 15 '22 22:11

Matt S


Building a PDF is always very long. If you have a huge amount of ressource, it will be very very long, you can't avoid that. I can see one way of doing it a way that is softer for your users :

Sending them a html render, and then with Ajax make the pdf generation asynchronous. So you can display a status bar. and inform your users your are performing their demand.

Then the generation can be technicaly performed by three ways :

  • using fpdf and hard coding the disposition
  • using dom2pdf or such a library to make your html render a pdf file
  • create a latex string and then using proc_open to ask the latex compilator to build a pdf file. It is a really fast and reliable tool but it needs you to have a dedicated server and not a shared host.
like image 1
artragis Avatar answered Nov 15 '22 22:11

artragis