PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old November 18th, 2002, 01:23 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Adobe Acrobat Files from PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway