Which one of these is the best PDF-API for PHP?
-
6this other question seems to be removed from StackOverflow now. – rineez Aug 07 '12 at 06:36
-
i know its old question, but i would prefer MDF, it can handle any complex html, excluding a few points that is already told by mdf at http://www.mpdf1.com/mpdf/limitations – dev.meghraj Sep 06 '13 at 07:00
-
Here you can see a [good comparison between mPDF & TCPDF](https://www.favor.com.ua/blogs/9592.html?export=pdf) – Peyman Mohamadpour Jan 09 '17 at 17:45
9 Answers
personally i'd rather go with tcpdf which is an ehnanced and mantained version of fpdf.

- 13,055
- 9
- 48
- 61
-
14you didn't specify reasons - one huge one is Unicode support in tcpdf, which fpdf utterly lacks. tcpdf is also still actively maintained. and, it's also got a decent OO architecture. word to the wise: fpdf is basically an old thing that got superseded by tcpdf. – zanlok Dec 13 '10 at 22:18
-
2tcpdf is missing critical features like font embedding and subsetting (important for asian languages). – velcrow Aug 31 '11 at 22:33
-
2i just checked the tcpdf website and it does seem to support font subsetting and embedding. see the subset argument to the SetFont method http://www.tcpdf.org/fonts.php – Abbas Gadhia Jul 21 '12 at 11:14
-
1
-
2If you call a single class with 24k lines of code "decent OO" you must be high. Check out my refactored version of FPDF for actual OOP : https://github.com/bubach/PdfBuilder – Christoffer Bubach Apr 14 '16 at 18:51
From the mpdf site: "mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF, with a number of enhancements."
mpdf is superior to FPDF for language handling and UTF-8 support. For CJK support it not only supports font embedding, but font subsetting (so your CJK PDFs are not oversized). TCPDF and FPDF have nothing on the UTF-8 and Font support of mpdf. It even comes with some open source fonts as of version 5.0.

- 6,336
- 4
- 29
- 21
This is just a quick review of how fPDF stands up against tcPDF in the area of performance at each libraries most basic functions.
SPEED TEST
17.0366 seconds to process 2000 PDF files using fPDF || 79.5982 seconds to process 2000 PDF files using tcPDF
FILE SIZE CHECK (in bytes)
788 fPDF || 1,860 tcPDF
The code used was as identical as possible and renders just a clean PDF file with no text. This is also using the latest version of each library as of June 22, 2011.

- 321
- 3
- 2
-
5There are a number of performance enhancements that can massively improve the TCPDF speed (I went from 1 minute in creating a single file to about 0.5 seconds): http://www.tcpdf.org/performances.php – Dan Smart Mar 15 '12 at 08:25
-
2Those "enhancments" will work equally well with FPDF and won't really help in a benchmark. TCPDF is about 24 000 lines of code, while FPDF is about 2400 lines of code. – Christoffer Bubach Mar 28 '16 at 04:08
-
I found mpdf better than tcpdf in terms of html rendering. It can parse css styles much better and create pdf that look very similar to the original html.
mpdf even supports css things like border-radius and gradient etc.
I am surprised to see why mpdf is so less talked about when it comes to html to pdf.
Check out the examples here http://www.mpdf1.com/mpdf/index.php?page=Examples
I found it useful for designing invoices, receipts and simple prints etc. However the website itself says that pdfs generated from mpdf tend to be larger in size.

- 2,877
- 25
- 35

- 1,086
- 14
- 19
-
3Link is broken. This might be new link: http://www.mpdf1.com/mpdf/index.php?page=Examples – Stefan Jun 05 '15 at 21:33
-
-
mpdf unfortunately doesn't seem to handle large table cells well. As soon as the content exceeds a page, it starts to scale down, which makes it useless for any project that has big tables. Apart from that; it's easy to use, performant, and well documented. – zumek Dec 31 '19 at 01:30
-
mpdf is also super slow importing css files when using a hardware firewall, taking around 10 to 20 seconds per css file. That's not acceptable. – Vincent May 09 '22 at 17:39
Try TCPDF. I find it the best so far.
For detailed tutorial on using the two most popular pdf generation classes: TCPDF and FPDF.. please follow this link: PHP: Easily create PDF on the fly with TCPDF and FPDF
Hope it helps.

- 25,063
- 15
- 119
- 120
-
Crushes sometimes in Firefox with connection reset. Haven't check with the other browsers though. – kta Sep 13 '14 at 02:21
Personally I prefer to use dompdf for simple PDF pages as it is very quick. you simply feed it an HTML source and it will generate the required page.
however for more complex designs i prefer the more classic pdflib which is available as a pecl for PHP. it has greater control over designs and allows you do do more complex designs like pixel-perfect forms.

- 140,109
- 3
- 41
- 60

- 3,499
- 5
- 24
- 32
-
1But there is a cons of using dompdf is that it doesn't work if you want to create multiple pdf at once or in a loop. – hmjha Aug 05 '17 at 05:27
http://sourceforge.net/projects/html2ps/, is the best if you need the css and 3c compatibily.
if you can install software on your server, i suggest you to use http://wkhtmltopdf.org/.
There is also a drupal module using wkhtmltopdf :)
PHP take many resources to convert html in pdf, imho, php is not the right language to do that (if you expect a large numbers of coversion or large files to convert)

- 10,597
- 5
- 44
- 45

- 18,807
- 29
- 92
- 131
-
I upvote for wkhtmltopdf, but especially when using a method like employing an outside converter PHP is not to blame for loss of speed. I would think that using wkhtmltopdf or prince from asp.net would be practically equally fast as from PHP (although I use asp.net). Sure, PHP doesn't have all the process control of .net, but I would bet it still works fast enough for most projects – Joel Peltonen Aug 28 '12 at 09:43
The Zend Framework's Zend_Pdf is really good. It's on par with pdflib in terms of control of output and complexity and is more portable because its a pure php solution. That said, its slower and uses more memory than pdflib. Pecl modules are always more efficient than a php solution.
DOMPdf is the easiest way to make a pdf quickly. Like Mike said, feed it html and it outputs a pdf. Under the hood, it has the option to use either r&ospdf or pdflib as the rendering engine.

- 10,597
- 5
- 44
- 45

- 6,680
- 1
- 44
- 46
-
1Zend PDF has significant (performance issues if you embed PNGs with transparencies)[http://framework.zend.com/issues/browse/ZF-3392]. Also Zend PDF is a very bad tool for changing meta-data on 3rd party PDFs because it cannot handle anything close to the full PDF standard and it crashes. However, if you do not need these features Zend PDF works pretty well and has good UTF-8 support. – chrishiestand Nov 15 '12 at 19:16
I personally generate XSL:FO from PHP and use Apache FOP to convert it to PDF. Not a PHP-native solution, not very efficient either, but it works well even if you need to generate PDF with very complex layouts.

- 40,587
- 6
- 104
- 126