Specifications
LISTING 30.4 Continued
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-Disposition: filename=cert.pdf”);
header( “Content-type: application/pdf” );
$date = date( “F d, Y” );
// open our template file
$filename = “PHPCertification.pdf”;
$fp = fopen ( $filename, “r” );
//read our template into a variable
$output = fread( $fp, filesize( $filename ) );
fclose ( $fp );
// replace the place holders in the template with our data
$output = pdf_replace( “<<NAME>>”, strtoupper( $name ), $output );
$output = pdf_replace( “<<Name>>”, $name, $output );
$output = pdf_replace( “<<score>>”, $score, $output );
$output = pdf_replace( “<<mm/dd/yyyy>>”, $date, $output );
// send the generated document to the browser
echo $output;
}
?>
This script produces a customized version of our PDF document. The document, shown in
Figure 30.6, will print reliably on numerous systems, and is harder for the recipient to modify
or edit. You can see that the PDF document in Figure 30.6 looks almost exactly like the RTF
document in Figure 30.5.
Building Practical PHP and MySQL Projects
P
ART V
764
36 7842 CH30 3/6/01 3:40 PM Page 764