PDF is a popular, versatile format for storing content. PDF files can be generated once, and distributed in peace knowing that they will look the same across all platforms. They also serve as a perfect way of allowing your users to download or email a page from your website. In this tutorial, I'll show you how to generate PDF files in pure PHP and distribute your content in a single, consistent format.
Ever wanted to generate PDF files in your web application? You could let your users download pages in PDF format, generate PDF reports to be distributed in your organisation, or just get better control over how your pages look when printed. In this tutorial, we'll work through building a simple page and saving it as a PDF file.
We'll be using the FPDF library to generate our PDF files. The library is a simple PHP class that provides some very complex PDF generation functionality. Luckily, it offers some high level methods that you can use to quickly and easily generate PDF files without having to understand the internals of the PDF format.
Hands on The Portable Document Format (PDF) and Microsoft's Excel spreadsheet are commonly used for presentation of reports and data.
PHP, meanwhile, has become one of the most commonly used scripting languages on the web today, with 35 per cent of web sites running PHP. The TIOBE index of programming languages also indicates an increase in the usage of PHP.
Generating PDF’s is an easy method to make a very nice printable and/or savable version of an article. This could be helpful in a WordPress blog or any articles website. This method utilizes the popular FPDF class.
Sometime last week on the framework mailing list there was an interesting discussion on HTML to PDF. (those wacky framework guys always have the most interesting conversations) It was a rousing discussion as these things go and it it ended with the conclusion that reliable HTML to PDF is darned near impossible without implementing a full-blown rendering engine. Understandable given the intricacies of HTML. I mean even FireFox and IE can’t agree on how to render some pages. But sometimes you’ve just got to have your PDF. Well, here’s one way you can.
Use these functions instead if you want to create a FDF file without installing the FDF toolkit. You would use it the same way as the fdf_* functions. BTW, I only wrote the basic library functions for creating FDFs.
In last month’s issue, Marco Tabini examined the structure and contents of a PDF document in considerable detail. This month, he'll show you how to actually write a PHP library capable of opening one and modifying its contents programmatically.
We have seen in Part 1 how PDF files are, after all, just plain text files, with specific markup syntax that describes what should happen to objects within the document, such as text and images. We shall now further examine this syntax, to allow us to create a more complete PDF document (i.e more than simple text).
This tutorial is intended for the PHP programmer who needs to incorporate PDF generation in a script without using external libraries such as PDFlib (often unavailable due to licensing restrictions or lack of funds).
This tutorial will cover only the basics, which hopefully will give you a good start. PDF has a vast set of features and possibilities which can not be covered in a short tutorial. If you need more than what is covered here, you might want to look at some similar yet more complete solutions available, such as the excellent work done by Olivier Plathey on the FPDF class (http://fpdf.org), on which this tutorial is based.
What should be considered when one in given the task of generating PDF reports? Daryl will explain some aspects that come with this daunting task.
The php_pdf.dll extension is enough to produce pdf files on the fly. Once you have read this article you may start to produce high quality pdf files for your clients.