13.09.2016 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Solution Components<br />

To get the system working, you need to be able to examine users’ knowledge <strong>and</strong><br />

(assuming that they pass your test) generate a certificate reporting their performance. For<br />

this project, you experiment with generating this certificate in three different ways: using<br />

an RTF template, using a PDF template, <strong>and</strong> creating a new PDF programmatically.<br />

Let’s look at the requirements of each of these components in some detail.<br />

Question <strong>and</strong> Answer System<br />

Providing a flexible system for online assessment that allows a variety of different question<br />

types, various media types for supporting information, useful feedback on wrong<br />

answers, <strong>and</strong> clever statistic gathering <strong>and</strong> reporting would be a complex task on its own.<br />

In this chapter, we are mainly interested in the challenge of generating customized<br />

documents for delivery over the <strong>Web</strong>, so we explain how to build only a very simple<br />

quiz system.The quiz does not rely on any special software. It uses an HTML form to<br />

ask questions <strong>and</strong> a <strong>PHP</strong> script to process the answers.You have been doing this since<br />

Chapter 1,“<strong>PHP</strong> Crash Course.”<br />

Document Generation Software<br />

No additional software is needed on the <strong>Web</strong> server to generate RTF or PDF documents<br />

from templates, but you need software to create the templates.To use the <strong>PHP</strong> PDF creation<br />

functions, you need to have compiled PDF support into <strong>PHP</strong>, a topic which is discussed<br />

later in this section.<br />

Software to Create RTF Template<br />

You can use the word processor of your choice to generate RTF files.We used Microsoft<br />

Word to create our certificate template, which is included on the CD-ROM in the<br />

Chapter 32 directory.<br />

If you prefer another word processor, it would still be a good idea to test the output<br />

in Word because the majority of your visitors will be using this software.<br />

Software to Create PDF Template<br />

PDF documents are a little more difficult to generate.The easiest way is to purchase<br />

Adobe Acrobat.This software allows you to create high-quality PDFs from various applications.We<br />

used Acrobat to create the template file for this project.<br />

To create the file, we used Microsoft Word to design a document. One of the tools in<br />

the Acrobat package is Adobe Distiller.Within Distiller, we needed to select a few nondefault<br />

options.The file must be stored in ASCII format, <strong>and</strong> compression needs to be<br />

turned off. After these options are set, creating a PDF file is as easy as printing.<br />

You can find out more about Acrobat at http://www.adobe.com/products/acrobat/.<br />

You can either buy it online or from a regular software retailer.<br />

Another option to create PDFs is the conversion program ps2pdf, which, as the name<br />

suggests, converts PostScript files into PDF files.This option has the advantage of being

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

Saved successfully!

Ooh no, something went wrong!