HTML to PDF vs. Programmatically creating PDF via PHP

pdf-generation, php

Solution

I can recommend Zend_Pdf, which is a programmatic method according to your classification.

A HTML abstraction is nice but I don't believe you have the full power and control of a full geometry based drawing API. Be wary of libraries like fpdf which don't support UTF-8 out of the box, and use a poor man's parser to 'convert' HTML to PDF.

With regard to your application, I have produced a system which generates templated invoices. My users can upload a PDF template, which is extracted by Zend_Pdf. This template is then used for every page of the invoice generated, allowing easy customisation.

Note that my audience are mainly graphic designers who are capable of producing these templates, so it was the appropriate solution here. If your audience are only familiar with HTML, 'converting' HTML to PDF might be the best way.

Problem

I have a PHP application that needs to generate some PDF invoices and PDF timesheets with nice headers/footers. Some Stackoverflow users recommend using TCPDF to create the PDF documents. In my research, I discovered two approaches to generating PDFs: 1) Programmatically formatting the PDF like so: ``` $tcpdf->SetFillColor(255, 0, 0); $tcpdf->SetTextColor(255); $tcpdf->SetDrawColor(128, 0, 0); $tcpdf->SetLineWidth(0.3); $tcpdf->SetFont('', 'B'); ``` 2) Converting HTML to PDF How do I decide which I approach I should use?

Original source