10

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 php 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.

JM4
  • 6,740
  • 18
  • 77
  • 125
  • In the way of commentary, I use FDPF, never tried the other. FPDF is crotchety and hard to get just right, then it runs like a champ. I had been toying with the idea of experimenting with TCPDF (due to the high recommendations it seems to get around here), but the file size difference is a deal-breaker. Good question, wonder if anyone will give a definitive answer. – Chris Baker Sep 15 '11 at 20:01
  • @Chris - thanks. I have never really had problems with FPDF and it always works well. I am in a bind either way really because I either have to give in to the new huge filesize (and is really slow right now) or rewrite for FPDF. – JM4 Sep 15 '11 at 20:06
  • 1
    i'd say the file is bigger because it contains more code and functions. should i post this as an answer? – Einacio Sep 16 '11 at 17:30
  • use what works for you, not what others like. half the world still uses IE6, so what? try both an decide what's best for you. the guys from tcpdf recommend using memcached or the like to fight back the library size – Einacio Sep 16 '11 at 17:45
  • Ahhhh, I thought you were saying the PDFs themselves are larger. Heh, need to read slower. The size of the library doesn't matter terribly much, and could be caused by a number of things. The TCPDF guys could have used loads more comments, the could use a different style of indentation/curlies that make more lines in the file. They could be less efficient in general, they could have more functionality... the size of a php file is like the cover of a book - nothing to judge by. – Chris Baker Sep 16 '11 at 19:02
  • @Chris - perhaps nothing to judge by but when my server has to open and read a 1MB file to 40Kb file, shouldn't it be of some concern? Especially if the file is opened and read hundreds of times a day. – JM4 Oct 03 '11 at 19:30

4 Answers4

5

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. :)

johndodo
  • 17,247
  • 15
  • 96
  • 113
  • thank you for your very helpful response. The filesize I am referring to however is in the actual php files (fpdf.php and tcpdf.php). What is the actual difference in these two files to make such an enormous difference? – JM4 Sep 16 '11 at 17:24
  • i just read the licence of TCPDF and it is GNU LGPL. can you direct me to the part where they say that about their logo in my PDFs? – Einacio Sep 16 '11 at 17:48
  • @JM4: oops, sorry, misread the question. As Einacio said, the difference is probably because of the added functionality. However, you shouldn't judge library by file sizes only. If it is not loaded you don't care much about that. – johndodo Sep 16 '11 at 19:31
  • @Einacio: http://www.tcpdf.org/license.php says: "Additionally, YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS." – johndodo Sep 16 '11 at 19:34
  • as far as i found, it's just the "Producer" field in the pdf properties, that includes an url. but i didn't found any logo or image. it doesn't intefere with my current use of the library, but i'll remember it for the future, thanks. i'll later check if i can modify the library itself under the terms of gpl so the field never gets into the pdf, so i wouldn't infinge it by removing it from the final document – Einacio Sep 16 '11 at 20:43
  • A friend used a current TCPDF and the big red logo was there, do you have an older version? Note that it doesn't say HOW you remove it - so there is really nothing you can do to avoid this clause. But you could put something over it, it doesn't say anything about visibility... ;) – johndodo Sep 22 '11 at 10:30
  • @johndodo: I followed your link to the license, and it appears to be a standard GPL3. I cannot find the additional clause you give anywhere in the text. Has it changed? If so, perhaps its worth modifying you answer to that effect. – beldaz Mar 25 '12 at 02:44
4

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.

Einacio
  • 3,502
  • 1
  • 17
  • 21
  • should I be worried about my server having to load a 1MB file versus 50KB file hundreds of times a day? – JM4 Sep 19 '11 at 21:51
  • as far as i understand gpl (the licence) you can remove all those comments as long as you preserve the one about the licence. then you'll have a 50k tcpdf. you can also use some opcode cache, like memcache, to avoid repeated compilation, even on the 50k file. but in general it shouldn't be a problem, unless it is loaded in every request to the server. – Einacio Sep 20 '11 at 14:51
0

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.

Nicola Asuni
  • 1,500
  • 16
  • 9
-1

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.

Nicola Asuni
  • 1,500
  • 16
  • 9
  • "X is better than Y" - that is a bogus statement and one which does not come close to pointing out how a 1 **megabyte** php file is more useful than using a 40 **kilobyte** file. Who cares if TCPDF can do **everything** from one script without needing to add new classes? I have yet to find anything TCPDF can do that I cant do in FPDF or that I cannot extend into FPDF myself easily. – JM4 Oct 03 '11 at 19:26