views:

12268

answers:

11

I'm wondering which is the best PDF creation library for PHP, mainly for creating PDFs from scratch (not as much HTML to PDF)?

I have worked with FPDF for quite a while now, but it's getting quite old and hasn't had much for updates. I found TCPDF the other day (thanks you another question on SO). It seems very good and is based on FPDF so I don't think it'd be a big transition. FPDI also supports TCPDF which is nice as I have used it before and found it be useful.

I have also seen DOMPDF but it too hasn't had many updates for quite some time and is lacking a lot of functionality for general PDF generation. Zend (Zend_Pdf) as well as many other libraries have their own PDF libraries or extend another one, but you often have to setup the entire library, which for existing projects can be a problem.

What other libraries are there and what have your experiences with them been with the above or other libraries?

+1  A: 

Try this one

http://www.fpdf.org/

What are you experiences with FPDF? I did mention it in the question.
Darryl Hein
A: 

I like pdflib

Pablo Santa Cruz
Too bad the full version is to terribly expensive.
Darryl Hein
Its a waste of money. TCPDF is the way to go, with far better features.
JasonMichael
+2  A: 

There is more info on this topic in Convert HTML + CSS to PDF with PHP?

I don't know from your question if you want to build PDFs from scratch. If so, that's not an area I've really looked into.

If however you want to convert HTML to PDF then that I can help you with because I've been doing lots of this for the last three months and I can unequivocally that the best product by far (by light years in fact) is Prince XML. It's quick, robust and, yes, it's expensive (USD 3800 for a server license).

I tried DOMPDF, HTMLDOC, html2pdf, etc and each had problems (more info in the above question). Prince just continues to blow me away. it's fast and has many many features that go beyond CSS 2.1 even.

It also passed the Acid2 test, which not even some browsers can claim.

cletus
+7  A: 

FPDF is functional enough and it can be extended easily.

DOMPDF is fine for basic HTML to PDF generation, I've used it with Smarty and it works well enough, but has some nasty bugs with tables and page breaks.

I haven't tried Zend or TCPDF.

Neil Aitken
+1 for mentioning DOMPDF bugs. I have been fighting them for some time.
Elijah
It occasionally cripples one of my invoice functions, i've had to put some rather odd looking page breaks into my templates to work around the overflow errors. Not sure if it's even being actively maintained anymore. Maybe time to find another
Neil Aitken
+1  A: 

I've used both PDFlib and fPDF. If you're making things for yourself, you can get a PDFlib license cheap, but if you're making something for a paying gig, either you or your client will have to pony up ~$1k for a license.

It was at that point that I started working with fPDF instead. I found both to be easy to work with, but I liked putting text at an x/y coordinate with PDFlib more than I liked the box-model that fPDF seems to use.

Can you describe the difference between the 2 models a bit more?
Darryl Hein
fPDF example: http://www.fpdf.org/en/tutorial/tuto1.htm. It's possible that there may be a better way. I have only used fPDF for one very small project so far.PDFlib: You can use the PDF_show_xy() to put text wherever you want.http://www.tu-chemnitz.de/docs/php.en/ref.pdf.html
+1  A: 

Having gone down the road of PHP + PDF (via libpdf), I would recommend staying away. Honestly, unless you need an immense amount of flexibility and have access to, or are up for writing, a very good layout manager, it is flat out a giant waste of time. You might be lucky in that what you're trying to produce is very simplistic.

I would recommend building up templates in OpenOffice, you could probably get away with hand coding them once, populating them from the PHP side, and then have OO output a PDF. More often than not, it'll look much better than anything produced automagically.

Mind you, the above might get hairy if you need to have an enormous amount of control.

Saem
I have been creating PDFs for 3 years and haven't found it to be that difficult. It's just like creating any other graphic or even a webpage that you are often dealing with a few pixels where or there. Populating templates of 500+ page PDFs would not work for clients.
Darryl Hein
+14  A: 

I do NOT like pdfLib or fPDF... TCPDF is by far the best one, especially if you need to get your work done in a reasonable amount of time (i.e. the boss needs PDF reports from your web application TODAY or this week). These other libraries require you to exactly position items and don't have HTML to PDF conversion. TCPDF does alot of the hard work for you, even if you need to write something using its multicell method. Its a very smart, fast library and will get the job done alot faster than many of the other libraries out there. Plus, it is being updated on a regular basis for PHP 4 and PHP 5 - just about every week there's a new update.

A developer who had my job, before me, used pdfLib - took weeks to create a couple reports, formatted the way the company needed them. Using TCPDF, I had ninety percent of some more advanced reports done in a few hours.

Also, TCPDF doesn't require anything to be compiled or added to your server - you just tar/unzip it to your server into an appropriate path, and its ready to go.

You can find example of TCPDF here.

JasonMichael
Thanks for the advice.
garcon1986
+3  A: 

I personal recommend command line application instead of any php libraries.

Reasons :

  1. PHP libraries need more time and memory (cache) for conversion process

  2. They need well formatted html pages only, otherwise through errors or warning

  3. Not support for external style sheet.

Command Line Tool:

  1. If run your script on Linux server then I suggest command line tool.

Reasons :

  1. They are extremely fast as compared to PHP libraries.

  2. Support css.

  3. Accept non well formatted html.

Which command line tool to use?

  1. wkhtmltopdf
  2. htmltopdf
  3. html2pdf

for more information refer http://stackoverflow.com/questions/1403820/html-to-pdf-not-pdf-to-html-in-php

santosh
+1  A: 

PrinceXML is an amazing PDF generation tool and can be easily integrated into PHP applications using the provided scripts. It comes with a high price tag, but the output is beautiful. Create your documents in HTML and use CSS to style your documents. You can do impressive page flow, page numbering, headers etc all in CSS.

PrinceXML

James Hall
+1 for PrinceXML, it's absolutely worth the price. The results are stunning and it works like a charm. It integrates extremely well with the server environment, font libraries, etc. It understands a lot of CSS and it is extremely fast.
tharkun
A: 

tcpdf sucks like a baby.. its too damn slow in generating dynamic pdf.. fpdf is somaritively better i beleive.. i've not used dom, though...

nadiq
A: 

I have used ezpdf for several small projects with no problem. http://www.ros.co.nz/pdf/

MiJaMu