PDF Extensions

PHP has several libraries for generating PDF documents. This chapter shows how to use the popular FPDF library. The FPDF library is a set of PHP code you include in your scripts with the require function, so it doesn’t require any server-side configuration or support, meaning you can use it even without support from your host.

The basic concepts of the structure and features of a PDF file should be common to all the PDF libraries, however. This FPDF library is available here.

Note

There is another PDF-generating library called TCPDF that is better at handling HTML special characters and UTF-8 multilanguage output. Look this up if you have that kind of a need. The methods you will be spending time with will be writeHTMLCell and writeHTML. You can find the library here.

Get Programming PHP, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.