
November 18th, 2002, 01:23 PM
|
|
Contributing User
|
|
Join Date: Nov 2002
Posts: 91
Time spent in forums: < 1 sec
Reputation Power: 6
|
|
|
Adobe Acrobat Files from PHP
Hi, I'm having a spot of bother with a PDF creation script I'm using (originally found it in an IBM DeveloperWorks Book and modified it to suit me). The purpose is to take a template pdf file and insert values into it before sending it to the browser.
I am running Apache 2.0.42 and PHP 4.30-dev on Windows XP Pro with the php_pdf.dll extension loaded.
The code is listed below:
PHP Code:
<?php
set_time_limit(180); //script can run 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);
}
if(!isset($content)||!isset($author)||!isset($blog title))
{
echo "This was not called correctly";
}
else
{
//generate headers to help browser choose the correct application
header ("Content-Disposition: filename=entry.pdf");
header ("Content-type: application/pdf");
//open our template file
$filename="blogtemplate.pdf";
$fp=fopen($filename, "r");
//read our template into a variable
$output=fread($fp,filesize($filename));
fclose($fp);
//replace the placeholders in our template with our data
$output=pdf_replace("<<BLOGTITLE>>",strtoupper($blogtitle),$output);
$output=pdf_replace("<<Author>>",$author,$output);
$output=pdf_replace("<<Content>>",$content,$output);
//Send modified document to the browser
echo $output;
}
?>
The problem I have is that when all the variables are set properly, the page invokes Adobe Acrobat, but I get an error message saying "The File is damaged and could not be repaired."
Do you know of anything that might be the problem here? What I am maybe thinking is that there might be a problem with permissions reading the template? Any help would be greatly appreciated.
Also, I've tried commenting out the headers, same problem, all it does differently is that it prompts me to download the file, not display it inline within the browser. I'm thinking maybe it's that PHP has problems with Acrobat 5 files?
|