I want to generate PDF from a PHP file that includes HTML controls like textbox, and textarea. I attached CSS in the same. I tried FPDF, DOMPDF and TCPDF, but still I don't get exactly what I want. How do I pass HTML controls with PHP variables and CSS to these libraries?
-
1I have used `TCPDF` before, but I think [`MPDF`](http://www.mpdf1.com/mpdf/) is really great and feature rich and well-documented. I want to give it a try ASAP. – Peyman Mohamadpour Jan 01 '17 at 07:51
-
Off-topic on SO, but on-topic in softwarerecs.SE: https://softwarerecs.stackexchange.com/q/45903/1834 – Martin Thoma Sep 21 '17 at 15:06
4 Answers
mpdf is another option that you could try.

- 698
- 7
- 19

- 209,507
- 32
- 346
- 385
-
1I also came here looking for a decent solution, mpdf is great and the [manual](http://mpdf1.com/manual/index.php) is user friendly – proPhet Jan 23 '14 at 09:56
-
-
1@themis - what happened is that mpdf migrated to https://github.com/mpdf - these things happen over the years – Mark Baker Apr 06 '17 at 16:40
-
I struggled quite a bit with dompdf (mostly because of custom fonts and missing documentation). Then I changed to mpdf and since then my life is much better :) – Motine Dec 13 '21 at 11:43
EDIT : Found another solution for it, TCPDF is a FLOSS PHP class for generating PDF documents. Looks more dominating library.
"PRINCEXML" is a good library (not completely free now).
Others:
If your meaning is to create a PDF file from PHP, pdflib will help you (as some other suggested).
Else, if you want to convert an HTML page in PDF via PHP, you'll find a little trouble outta here.. For three years I have been trying to do it as best as I can.
So, the options I know are:
HTML2PS: same of DOMPDF, but this one convert first in .ps (Ghostscript), then, in whatever format you need (PDF, JPEG, PNG). For me it is a little better than dompdf, but I have the same speed problem.. Oh, it has better compatibility with CSS.
Those two are PHP classes, but if you can install some software on the server, and access it through passthru() or system(), have a look at these too:
wkhtmltopdf: based on webkit (safari's wrapper), is really fast and powerful... It seem like it is the best one (atm) for converting HTML pages to PDF on the fly, taking only two seconds for a three pages XHTML document with CSS 2. It is a recent project. Anyway, the Google Code page is often updated.
htmldoc: this one is a tank, it really never stops orcrashes... The project seems to have died in 2007, but anyway if you don't need CSS compatibility this can be nice for you.
** Thumbs Up For Strae.

- 1
- 1

- 3,050
- 1
- 27
- 37
-
Another option is [PD4ML](http://pd4ml.com/php.htm): platform-independent Java library with a PHP wrapper script. Supports HTML/CSS/SVG conversion to PDF, RTF and raster images – zfr May 24 '13 at 22:09
If I understand your needs correctly I don't think any PHP-PDF class would do that.
Mostly you could insert only text and images to a PDF file, so if you would want something that looks like an HTML element you would need to insert it as an image.
Usually just putting HTML doesn't mean all your elements would stay intact in the PDF . (Different world, after all)

- 21,321
- 22
- 95
- 134

- 9,224
- 4
- 56
- 83
http://www.fpdf.org/ is the site having a great HTML-to-PDF class which work well. I am using it, but you have to first study its functionality and then start.

- 30,738
- 21
- 105
- 131

- 1,876
- 12
- 20