I know there have been a lot of posts about these two but figured I'd address a glaring question I have. A designer of ours recently sent me a few files with TCPDF already tied in because a friend of him said it was "better".
In the past we have used FPDF for everything PDF generation in PHP but right off the bat I noticed an enormous glaring difference:
Filesize of fpdf.php: 46KB
filesize of tcpdf.php: 996 KB
note: the file sizes above are of the actual 开发者_如何学Cphp file, not the PDF's generated.
I don't really have too much patience to sit down and look at all of the differences between the two but it doesn't seem it is worth the switch really for the huge file difference. Most on SO seem to really like TCPDF but what gives?
Main Question
Why the difference in size and should I be worried for my server having to load a 1MB file hundreds or thousands of times a day versus a 50KB file that does nearly the same thing? I am NOT saying my PDF file larger here folks. The filesize of the PHP script itself is the 1MB to 40Kb.
I avoid TCPDF because of its unfriendly license (you must leave link + logo intact in generated PDF documents). (Note: it seems the license has changed and is now standard LGPLv3: http://www.tcpdf.org/license.php)
That said, the usual cause for larger file size is embedded fonts. You can specify fonts in several different ways:
- specify them and do not embed them (smallest size, however, text might not display correctly)
- embed them fully (FPDF already supports this)
- embed just the parts of characters that are used
The first option produces smallest files - I guess this is what you use with FPDF. Note that your PDF might display differently on different systems.
The second option produces largest files. Since the font is there it is (in theory - I have no experience with this) possible to edit file and add text in the same font.
The third option is the one that should be used in most cases, however, it is the most difficult to implement in libraries and core FPDF does not support it (TFPDF however does). It only embeds glyphs that are used so it produces cross-platform PDFs which are quite small.
The third option was not supported with TCPDF a few years ago (however, this might have changed by now). As I mentioned, it is also not supported in core FPDF - however, it is supported in MPDF and TFPDF (which I have successfully used in many projects).
On a side note, another reason for me not using TCPDF was unfriendly and unhelping attitude of mr. Asani (developer) in contrast with FPDF / MPDF / TFPDF community (Oliver, Ian,...) help on FPDF forum. It took 2 weeks of correspondence on forum before he admitted that TCPDF does not support partial font embedding. However, it is the license that is a real deal-breaker to me.
So, to answer your question: you could make TCPDF produce smaller files by not embedding fonts. However the license should be the main reason for switching from it. :)
i took an instant to compare both sources.
fpdf has almost no comments.
tcpdf has a few more methods but also has full blocks of phpDoc-like comments with explanations of every parameter and usage and examples in html format before every method and property. i'd say that's the main reason for the big file size.
Note that the sentence "YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS" on the TCPDF license, refers only to an INVISIBLE link (metadata) and not on the header logo and links that appears on the default examples. This means that the documents produced with TCPDF doesn't contain any visible artifact that interfere with your document layout.
Then, to answer your question, the document size depends by the new features you are using that are not present in FPDF. If you don't need some features and you want to reduce the document size, then disable Unicode, use only core fonts like helvetica and apply the other tips at http://www.tcpdf.org website.
TCPDF contains hundreds of features more than FPDF, that's why it's bigger (and better). FPDF is a very primitive library compared to what TCPDF is and what it can does.
精彩评论