Jump to content

generating pdf _ trouble


jakebur01

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.