PDF generation ( Using PDF templates on the fly )

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kirkham99
Forum Newbie
Posts: 4
Joined: Tue Mar 11, 2003 10:58 am

PDF generation ( Using PDF templates on the fly )

Post by kirkham99 »

I wonder if you could help, I have a question of using PHP -> PDF templates

I have written 3 simple scripts one to use an RFT as a template and resolve variables on the fly and also a version using PDFLIB functions and they both work OK.

The problem is I want to use PDF templates and resolve variables on the fly, and I keep getting the same error message from the web browser "The file is damaged and could not be repaired". I am using Acrobat 5.0

By the way, the script works fine if I comment out the PDF_REPLACE option. I assume these are causing some type of error?? I tried updating the Acrobat prefences/options to not load in a Browser but that just downloaded to my PC and the same error message appeared after I double clicked on it...

The PDF template small script is attached.

<?php

set_time_limit( 180 ); // this script can be very slow

//create short variable names
$name = $HTTP_POST_VARS['name'];
$score = $HTTP_POST_VARS['score'];

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;
}
?>

Rgds
sitydwella
Forum Newbie
Posts: 1
Joined: Sun Jun 22, 2003 10:03 pm

PDF Mod needed

Post by sitydwella »

Do you think you could develope a mod for this site?:

:arrow: http://ldu.neocrome.net

Check it out :!:

Check out the urbanpromoter journals on the site
User avatar
hyper_st8
Forum Newbie
Posts: 20
Joined: Mon Aug 18, 2003 5:27 am
Contact:

Post by hyper_st8 »

I am having the same problem, can't seem to do anything with adobe 5 created documents. Did you manage to sort this problem?
Post Reply