I m having problems with DOMPDF that If I want to create a big pdf file It takes a hell lot of time. I have observed that my pdf option in print dialog box creates pdf very fast. or any third party software like createPDF or pdf995 creates pdf very fast. Can I use any of this kind softwares and call them through PHP by passing HTML to them and get a pdf back saved in my root directory. I m using a Linux Hosting where I can install this kind of softwares.
-
If you're using _shared_ Linux hosting then you'll only be able to install PHP libraries, in general. However if you have a VPS or a dedicated box, then talk to your sysadmin/host - they will help you install what you need. – halfer Apr 11 '12 at 20:59
-
Btw, if you are creating reports, then check out Jasper Reports. It's a Java stack and needs a spare host to run on, but you can call it from PHP and it's pretty great in terms of what it can do. I've used it alongside iReport, which is report designing software - and the community edition is all free! – halfer Apr 11 '12 at 21:00
2 Answers
What you are looking for is WKHTMLTOPDF. Don't bother with DOMPDF etc, it's not worth the time spent. WKHTMLTOPDF produces the best results server side and quite fast (depending on the server specs).
You can run WKHTMLTOPDF (and other software) headless with a virtual X server to get results like you are used with your "print dialog" (it's based on WebKit).
You might waht to check my other post here: HTML2PDF in PHP - convert utilities & scripts - examples & demos
(if you scroll to the bottom thare's some PHP code very suitable for your needs)
-
1`wkhtml2pdf2` is pretty good (and free!) but the company I work for assessed it and found that it didn't handle page breaks very well. We went with Prince in the end, which is expensive, but does orphan control better. That might be something for readers to bear in mind before they choose their PDF platform. – halfer Apr 11 '12 at 11:27
-
well, yea, that might be a point. however I had no problems with the breaks, but I am aware of this. I think this is more of an issue with very long documents. – Michal Apr 11 '12 at 11:29
-
To be fair, the work I've done in Prince - which often features rowspans longer than a single page - worked _okay_. I personally still think the table/page breaking would have been better in something like Jasper... but we sometimes have to work within the technology constraints we are handed! – halfer Apr 12 '12 at 10:18
PHP is a slow language (compared to compiled code) so if your PDF generator (as DOMPDF is) written in PHP, of course it will be slow compared to a C++ executable version. Good news is that the answer is Yes, you can do exactly what you have alluded to. PHP has the ability to run system commands using the exec()
function, so you can use any command line tool capable to creating a PDF from your input (HTML) and then open and pipe the result to the browser as a downloadable file.

- 3,994
- 1
- 26
- 33