creating a pdf
Posted: Thu Apr 20, 2006 3:48 am
I am trying to create a pdf file of a quote drawn from a database.
To start with i'm trying to get one variable from the address bar to show in a pdf template i created. The template and code was obtained from a php book i have.
Here is the php code:
As you can see i'm just trying to use the one variable $number and insert it into it's place holder <<NUMBER>> which is in the given template pdf file.
All i get as output in the browser is :
Any idea where i'm going wrong?
To start with i'm trying to get one variable from the address bar to show in a pdf template i created. The template and code was obtained from a php book i have.
Here is the php code:
Code: Select all
<?php
set_time_limit( 180 ); // this script can be very slow
//create short variable names
$number = $_GET['orderno'];
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(!$number)
{
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=test.pdf');
header( 'Content-type: application/pdf' );
$date = date( 'F d, Y' );
// open our template file
$filename = 'test.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( '<<NUMBER>>', strtoupper( $number ), $output );
// $output = pdf_replace( '<<cat>>', $prods, $output );
// $output = pdf_replace( '<<mm/dd/yyyy>>', $date, $output );
// send the generated document to the browser
echo $output;
}
?>All i get as output in the browser is :
Code: Select all
%PDF-1.4 %âãÏÓ 15 0 obj <> endobj xref 15 9 0000000016 00000 n 0000000805 00000 n 0000001070 00000 n 0000001281 00000 n 0000001527 00000 n 0000001815 00000 n 0000002057 00000 n 0000000640 00000 n 0000000476 00000 n trailer <]>> startxref 0 %%EOF 23 0 obj<>stream xÚb```e``îb