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:
  #1  
Old November 18th, 2002, 02: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: 17
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
  #2  
Old December 7th, 2011, 01:52 AM
Rick87Ju Rick87Ju is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 1 Rick87Ju User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 54 sec
Reputation Power: 0
the words there actually are, unless there is a space/tab/newline at the end of the file. Can you figure out why?

Reply With Quote
  #3  
Old December 29th, 2011, 03:26 AM
vanluc88 vanluc88 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 1 vanluc88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 54 sec
Reputation Power: 0
thanks

thanks you very much
Quote:
Originally Posted by Kanu
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
  #4  
Old March 1st, 2012, 07:21 AM
Struble2010 Struble2010 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 5 Struble2010 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 18 sec
Reputation Power: 0
Appreciate the post. Thanks

Reply With Quote
  #5  
Old March 2nd, 2012, 03:33 AM
Donald24 Donald24 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 7 Donald24 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 38 sec
Reputation Power: 0
Haha, I think I'll just try EasyPHP, that is supposed to have everything covered. Still stumps me though why the stupid thing shows source code instead of the execution of a simple script php.

Reply With Quote
  #6  
Old March 9th, 2012, 06:30 AM
fengwilson fengwilson is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 1 fengwilson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 57 sec
Reputation Power: 0
Hi

Hello, I am new to the forum.

Reply With Quote
  #7  
Old March 11th, 2012, 09:55 PM
hhqsfgb7k hhqsfgb7k is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 6 hhqsfgb7k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 24 sec
Reputation Power: 0
Thank you Admin. Your site honey. I am sorry for my English, I only the beginnings to study it recently687360


Reply With Quote
  #8  
Old March 29th, 2012, 12:44 AM
Asgory4t Asgory4t is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 1 Asgory4t User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 37 sec
Reputation Power: 0
to study it recently687360

Reply With Quote
Reply

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


Developer Shed Advertisers and Affiliates


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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap