Ever wanted to generated PDF documents on the fly with PHP? Perhaps populate a standard contract with a customers name and address? FPDF and FPDI are two neat libraries which greatly helps when working with PDF files. FPDF is the main library for handling PDF files, while FPDI lets your import existing PDF documents into the FPDF documents. In the code sample I’ve prepared here I’m importing a PDF template document, writing some information to the document, then sending it to the “customer”. FPDF offers several neat ways to expose the generated document, such as a stream to the browser, a string, or just storing it to file. You can download PDF Sample code to test it.

Be sure to head on over to the FPDF site and FPDI site for more information on these two libs.

Related posts:
Generated PDFs over HTTPS with Internet Explorer

[tags]PHP,PDF,Frameworks[/tags]

One of the applications I’ve been working on generates PDF files which the customer can download. I’m using the FPDF and FPDI libraries to import PDFs and create copies with generated contents. This has been really easy to code, and it’s been working flawlessly in both Firefox and Safari. When we started testing under Internet Explorer thing started breaking. The problem was that IE would not let the user download the file. The only feedback we got was error messages like “The file is currently unavailable or cannot be found. Please try again later.” and “The file could not be stored in cache”. After spending some time debugging I found out that IE has problems with file downloads over HTTPS. Google pointed me to this post. The guy in that post spent six hours figuring it out, and he probably saved me six hours as well. The magic required to satisfy Internet Explorers needs:

1
2
header('Cache-Control: maxage=3600');
header('Pragma: public');

Spread the message so others can spare some time!