Specifications
When we have finished the whole PDF document, we need to close it using pdf_close().
When we are generating a file, we also need to close the file.
The lines
pdf_close($pdf);
fclose($fp);
complete the generation of our Hello World document. All we need to do is provide a way to
download it.
echo “download the pdf <a href = ‘hello.pdf’>here</a>”;
This example was derived from the C language example in the PDFlib documentation and
should provide a starting point.
The document we want to produce for the certificate is more complicated, including a border,
a vector image, and a bitmap image. With the other two techniques, we added these features
using our word processor. With PDFlib, we must add them manually.
Generating Our Certificate with PDFlib
In order to use PDFlib, we have chosen to make some compromises. Although it is almost cer-
tainly possible to exactly duplicate the certificate we used previously, a lot more effort would
be required to generate and position each element manually rather than using a tool such as
Microsoft Word to help lay out the document.
We are using the same text as before, including the red rosette and the bitmap signature, but we
are not going to duplicate the complex border.
The complete code for this script is shown in Listing 30.6.
LISTING 30.6 pdflib.php—Generating Our Certificate Using PDFlib
<?
if(!$name||!$score)
{
echo “<h1>Error:</h1>This page was called incorrectly”;
}
else
{
//generate the headers to help a browser choose the correct application
header( “Content-type: application/pdf” );
header( “Content-Disposition: filename=cert.pdf”);
$date = date( “F d, Y” );
Building Practical PHP and MySQL Projects
P
ART V
770
36 7842 CH30 3/6/01 3:40 PM Page 770