jakebur01 Posted September 7, 2007 Share Posted September 7, 2007 I am having trouble generating a .pdf . I have a html page with several form fields, I am only posting two fields to php for testing purposes. I created a .pdf named PHPCertification.pdf with <<NAME>> <<Name>> <<score>> <<mm/dd/yyyy>> in the text. Here is my php code: <?php set_time_limit( 180 ); // this script can be slow //create short variable names $SSC_COMPANY = $_POST['SSC_COMPANY']; $SSC_DATE = $_POST['SSC_DATE']; 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(!$SSC_COMPANY||!$SSC_DATE) { echo '<h1>Error:</h1><p>This page was called incorrectly</p>'; } 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>>', $SSC_COMPANY, $output ); $output = pdf_replace( '<<Name>>', $SSC_COMPANY, $output ); $output = pdf_replace( '<<score>>', $SSC_DATE, $output ); $output = pdf_replace( '<<mm/dd/yyyy>>', $date, $output ); // send the generated document to the browser echo $output; } ?> I get an acrobat message box saying that the file is damaged and could not be repaired. Link to comment https://forums.phpfreaks.com/topic/68366-generating-pdf-_-trouble/ Share on other sites More sharing options...
jakebur01 Posted September 7, 2007 Author Share Posted September 7, 2007 anybody? Link to comment https://forums.phpfreaks.com/topic/68366-generating-pdf-_-trouble/#findComment-343790 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.