zzzzprogram
Programmer
I am trying to get a script to work that replaces text from a PDF template. This template is a certificate that will be given to students upon completing an online training.
The script comes directly from the chapter 30 in the book, "PHP and MySQL Web Development" by Luke Welling & Laura Thomson.
The error message I get when the PDF file is opened in Acrobat Reader 5.0 is "There as an error processing a page. There was a problem reading this document (14)" and "Could not find the Extended Graphics State named 'GS1'"
Has anyone tried to use this script and already identified the problem or have any advice on ways to fix it?
Thanks for your help,
Laura
======================================
<?
set_time_limit( 180 ); // this script can be very slow
function pdf_replace( $pattern, $replacement, $string )
{
$len = strlen( $pattern );
$regexp = '';
for ( $i = 0; $i<$len; $i++ )
{
$regexp .= $pattern[$i];
if ($i<$len-1)
$regexp .= "(\)\-{0,1}[0-9]*\(){0,1}";
}
return ereg_replace ( $regexp, $replacement, $string );
}
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;
}
?>
The script comes directly from the chapter 30 in the book, "PHP and MySQL Web Development" by Luke Welling & Laura Thomson.
The error message I get when the PDF file is opened in Acrobat Reader 5.0 is "There as an error processing a page. There was a problem reading this document (14)" and "Could not find the Extended Graphics State named 'GS1'"
Has anyone tried to use this script and already identified the problem or have any advice on ways to fix it?
Thanks for your help,
Laura
======================================
<?
set_time_limit( 180 ); // this script can be very slow
function pdf_replace( $pattern, $replacement, $string )
{
$len = strlen( $pattern );
$regexp = '';
for ( $i = 0; $i<$len; $i++ )
{
$regexp .= $pattern[$i];
if ($i<$len-1)
$regexp .= "(\)\-{0,1}[0-9]*\(){0,1}";
}
return ereg_replace ( $regexp, $replacement, $string );
}
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;
}
?>