Easy PDF Generation in PHP
By Akash Mehta2008-03-01
Why would you want to generate PDFs?
When it comes to data output (not interface, output), web applications face an inherent problem: complex format and structures are very unreliable. For your complex reporting interfaces, you are faced with browser compatibility challenges, screen width issues and font size uncertainty. When it comes to demoing your latest version to your client, you may often find yourself embarassed by unforseen environment issues, and it's hard to tell a client their computer is broken.
At the same time, distributing reports - or any content, for that matter - from your web applications is also tricky. Users can try the "Save As" or "Save Page As" function in their browser, which will then attempt to calculate all the file dependencies and create an independent copy of the current page. Users will often distribute only the HTML page, losing all the CSS files and images - and with it, all hope of the end user viewing your data.
PDF as a format solves these problems wonderfully. When it comes to laying out a PDF document, you can simply assume it will look the same on your system as on the end user's. Screen resolution differences? Adobe Reader will scale beautifully. Images? SVG them and you'll have no problems; photographic data can cleanly resize. Browser versions? As long as they're all using Adobe Reader, or a reasonable alternative (such as Foxit Reader), you're fine.
Think of it like web design in a world where everyone uses Firefox.
Tutorial Pages:
» Introduction
» Why would you want to generate PDFs?
» Options for PDF Generation
» Hello World with FPDF
» Examining the code
» Further reading on FPDF
