13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

778 Chapter 32 Generating Personalized Documents in Portable Document Format (PDF)<br />

PDFlib is not free; it requires a commercial license. PDFlib Lite is available as open<br />

source <strong>and</strong> free, but only under certain conditions such as noncommercial use.<br />

Some free libraries, such as FPDF, are available. FPDF is not as feature rich as the<br />

commercial libraries, however. Also, because FPDF is written in <strong>PHP</strong> (rather than in C<br />

as a <strong>PHP</strong> extension), it is a little slower than the other two.You can download FPDF<br />

from http://www.fpdf.org/.<br />

In this chapter, we use PDFlib because it is probably the most commonly used PDFcreation<br />

extension.<br />

You can see whether PDFlib is already installed on your system by checking the output<br />

of the function phpinfo(). Under the heading pdf, you can find out whether<br />

PDFlib support is enabled, as well as the version of PDFlib used.<br />

If you intend to use TIFF or JPEG images in your PDF documents, you will also<br />

need to install the TIFF library, available from http://www.libtiff.org/, <strong>and</strong> the JPEG<br />

library, available from ftp://ftp.uu.net/graphics/jpeg/.<br />

The PDLlib extension is not built into <strong>PHP</strong>; you must obtain the files from PECL<br />

(<strong>PHP</strong> Extension Community Library) <strong>and</strong> install the extension manually.<br />

On non-Windows systems, obtain the extension by downloading the files at<br />

http://pecl.php.net/package/pdflib <strong>and</strong> installing using the pecl comm<strong>and</strong>. Please see<br />

the instructions at http://www.php.net/manual/en/install.pecl.pear.php.<br />

On Windows systems, obtain the precompiled extension (php_pdf.dll) by downloading<br />

the file at http://pecl4win.php.net/ext.php/php_pdflib.dll or by downloading the<br />

entire library of compiled PECL extensions from the <strong>PHP</strong>.net downloads page. Once<br />

downloaded, place the php_pdflib.dll file in your <strong>PHP</strong> extensions directory (usually ext<br />

within the <strong>PHP</strong> installation directory) <strong>and</strong> add the following line to your php.ini file:<br />

extension=php_pdf.dll<br />

Solution Overview<br />

In this project, you produce a system with three possible outcomes. As you can see in<br />

Figure 32.1, you ask quiz questions, assess the answers, <strong>and</strong> then generate a certificate in<br />

one of three ways:<br />

n<br />

n<br />

n<br />

An RTF document from a blank template.<br />

A PDF document from a blank template.<br />

A PDF document programmatically via PDFlib.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!