views:

970

answers:

6

I have a form with 5 fields, two of which are textboxes extended with tinyMCE, the rest are simple inputs of type text.

I need to generate a PDF from this input. I understand that I can use Zend_Pdf to generate the PDF and include the plain text data. But how, for example, can I include a bulleted list from the tinyMCE fields?

Would the best way be to create an HTML file, and then use for example DOMPDF or HTML2PDF? Ideally, I'd prefer to just use the zend framework to create the document, position and insert the fields, and save.

Thanks in advance.

+1  A: 

More info in Convert HTML + CSS to PDF with PHP?.

In my experience, Prince XML was the Rolls Royce of such technologies so far away and above any of the other ones it's not even funny. It's expensive though. But I had all sorts of problems with all the others.

cletus
+1  A: 

Some time ago I tried to use HTML to PDF conversion programs to convert... HTML to PDF, but in the end I gave up with that approach and just created the PDFs directly in code. I use fpdf (http://www.fpdf.org/) as a base and added supporting code for lists and grids etc.

Stacey Richards
A: 

You could convert it all to HTML and then use openoffice or some other tool (pandoc is quite nifty too) to convert from HTML to PDF.

Alternatively, you could take a look at LiveDocx, which has php-bindings too. It's a hosted service, but you can use it without charge.

troelskn
+1  A: 

I am using Prince XML mentioned by cletus. Results are very good, even with css styled html with floats etc. It's expensive, but it just works and saves a lots of time.

+1  A: 

FPDF is very old library for PHP4. It propably won't even work nowadays. I'd recommend DOMPDF or TCPDF. They both are for PHP5+ and can eat HTML or CSS to some degree.

raspi
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:

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