Hi all! I'm trying out this script I found in a book I bought. It does not work though.. The code is below. It looked like an easy solution for what I want to do. It takes a template PDF file and replaces <<description1>> with a value, <<bedr1>> with a value,... I want to be able to generate an PDF invoice automatically, based on a template PDF. I get this error: "The file is damaged and could not be repaired." Except when I comment out the 4 $output = pdf_replace( ....) lines.. then it works.. so something is wrong with the pdf_replace function.. If I open the PDF in Notepad I noticed it got cut off quite in the beginning of the file..
Does anyone have an idea? Or does someone know an other way to create PDF's based on a PDF, on the fly, using PHP?? Thanks! Mark. <? 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 ); } $description1="PDF creation module"; $bedrag1="240"; $total1="480"; //generate the headers to help a browser choose the correct application header( "Content-Disposition: filename=result.pdf"); header( "Content-type: application/pdf" ); $date = date( "F d, Y" ); // open our template file $filename = "template.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( "<<description1>>", $description1, $output ); $output = pdf_replace( "<<bedr1>>", $bedrag1, $output ); $output = pdf_replace( "<<tot1>>", $total1, $output ); $output = pdf_replace( "<<mm/dd/yyyy>>", $date, $output ); // send the generated document to the browser echo $output; ?> -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php