What is preferable to use? FPDF VS TCPDF
Asked Answered
O

4

7

So I have an assignment where I need to output the data from mysql database in PDF. And of course I am using PHP on this. I already started using FPDF since the first tutorial that popped up when I searched PHP to PDF on yt was FPDF.

The problem is there are some things that I need to do on PDF that I think FPDF can't do. Like different grids, fill color each grids and etc. And it was literally yesterday after I discovered that TCPDF exists! I visited the TCPDF page and I saw there that it is more wide that FPDF.

I know it is my fault that I didn't do enough research before I started coding. I just want to know what you guys thought is better. Should I stick on FPDF or go with TCPDF? Thanks.

p.s. please be nice

Oballa answered 27/2, 2019 at 5:11 Comment(0)
J
7

Just updates on the libraries mentioned above ...

1. TCPDF ( https://tcpdf.org ) - Last Update - v6.4.2 (2021-07-20)
2. FPDF ( http://www.fpdf.org ) - Last Update - v1.84 (2021-08-28) 
3. WKHTML2PDF ( https://wkhtmltopdf.org ) - Last Update - v0.12.6 ( 2020-06-11)

Do also consider headless chrome for state of the art CSS support and mirroring existing HTML pages to PDF. The php version is at https://github.com/chrome-php/chrome and requires PHP 7.3-8.0+ and a chrome/chromium 65+ executable.

Jobey answered 6/10, 2021 at 13:14 Comment(0)
V
5

Well if FPDF is missing some features you require, I would say the answer is clear... But to be honest neither of these projects are seeing much active development from what I can see. I've used FPDF before but most of the commits are ~3 years old, TCPDF has a few commits but very few.

Remote Option

I think what has happened is that most PDF generation is happening by utilizing HTML to PDF converters. If you google "html to pdf converter api" there are lots of APIs you can just post your HTML to and get a PDF back.

Local Option

If this isn't in your budget or want things local for other reasons. I use WKHTMLTPDF (uses webkit) but you'll obviously need some server admin fu to set this up. There are also some nice wrappers like spipu/html2pdf out there.

Veneaux answered 27/2, 2019 at 5:23 Comment(1)
By the way, FPDF lastest version 1.82 has been released : 07/12/2019. Odoo use WKHTMLTOPDF.Smitt
U
4

TCPDF is a great project. TCPDF > FPDF.

performance depend of your code. compare a multicell render, TCPDF is better. i generate pdfs with 1000 pages or more un seconds

$ pdf-> AddPage - 3 sek.

$ pdf-> writeHTML - 9 sek.

$ pdf-> Salida - 5 sek.

Unbalance answered 30/7, 2019 at 23:57 Comment(0)
S
4

TCPDF is based on FPDF and adds a few more methods, as you observed. I just checked my code and the methods I'm using in TCPDF that aren't available in FDPF are SetCellPadding, SetAlpha, WriteHTML and WriteHTMLCell. The HTML methods are especially useful if you want to display text that is already formatted with HTML.

The main downside to TCPDF is that its website and documentation are horrible, practically unusable. So even though I use TCPDF, I use the FPDF online documentation, and when something I'm looking for isn't there, I just look in the TCPDF code to see what it's doing.

Sarong answered 13/3, 2020 at 0:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.