TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-30-2009, 02:42 PM   #1 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default Output to PDF

Hey guys,

Just wondering if anyone here has any experience with generation PDF reports with PHP? Is this the best one to use?

http://www.fpdf.org/


I'm having a hard time understanding how it works.

For example, I have a website that generates a graph in flash. Then beneath the graph, I have rows upon rows of data to support the data in the graph.

Then there's also the layout of the webpage itself. So my assumption is that the PDF would look pretty much identical to the layout of the site, what you see on the webpage...

But I haven't got a clue how to go about this?

I currently have the data exported to CSV which is easy because I don't have to worry too much about formatting. But the PDF part is kinda confusing for me...

Help???
allworknoplay is offline  
Reply With Quote
Old 03-30-2009, 05:55 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

So what exactly is your question?
__________________

Village Idiot is offline  
Reply With Quote
Old 03-30-2009, 08:31 PM   #3 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
So what exactly is your question?

How to basically get my webpage along with the dynamically generated contents to be able to be exported to PDF....
allworknoplay is offline  
Reply With Quote
Old 03-30-2009, 09:19 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

I have never worked with fpdf before, but this tutorial might be of use http://www.id.uzh.ch/cl/zinfo/fpdf/tutorial/tuto1.htm
__________________

Village Idiot is offline  
Reply With Quote
Old 03-30-2009, 09:28 PM   #5 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
I have never worked with fpdf before, but this tutorial might be of use http://www.id.uzh.ch/cl/zinfo/fpdf/tutorial/tuto1.htm
yeah that's the problem. The example is a simple "hello world" type program and it's also in OO which I'm kinda weak in.

I guess I just don't conceptually understand how I can allow my users to export my PDF page in all it's glory via PDF.

As an example, imagine this website: www.talkphp.com

And imagine on the top corner it says: Export to PDF.

Then when you click on it and save it to your desktop and then open it, you basically get a screenshot of the main page....
allworknoplay is offline  
Reply With Quote
Old 03-30-2009, 10:50 PM   #6 (permalink)
The Wanderer
 
Join Date: Feb 2008
Location: Blackpool, England
Posts: 16
Thanks: 2
Andrial12 is on a distinguished road
Default

FPDF is the one to use. I used it for printing barcodes on a label printer many moons ago.
I'd suggest starting small, positioning text and lines etc. However I think that using any pdf API to draw anything more than simple pages will be like digging a hole with a spoon so to speak.

I'll have a look tomorrow see if I can dig out that code.
Andrial12 is offline  
Reply With Quote
Old 03-30-2009, 11:09 PM   #7 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Andrial12 View Post
FPDF is the one to use. I used it for printing barcodes on a label printer many moons ago.
I'd suggest starting small, positioning text and lines etc. However I think that using any pdf API to draw anything more than simple pages will be like digging a hole with a spoon so to speak.

I'll have a look tomorrow see if I can dig out that code.

Thank you I would really appreciate it...perhaps I can get idea's on how to do it after seeing some real live code....
allworknoplay is offline  
Reply With Quote
Old 03-31-2009, 12:21 AM   #8 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

http://www.digitaljunkies.ca/dompdf/
Enfernikus is offline  
Reply With Quote
The Following User Says Thank You to Enfernikus For This Useful Post:
allworknoplay (03-31-2009)
Old 03-31-2009, 02:18 AM   #9 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Enfernikus View Post

Thanks I will take a look.....
allworknoplay is offline  
Reply With Quote
Old 03-31-2009, 07:27 AM   #10 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

If you want to generate PDF's in PHP, I would recommed to use Haru, instead of FPDF, its well documented on php.net and is better supported, plus its not only available as a PHP binding.

PHP Binding: http://pecl.php.net/haru
PHP Binding Documentation: http://www.php.net/haru
LibHaru: http://www.libharu.org/
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
The Following User Says Thank You to Kalle For This Useful Post:
allworknoplay (03-31-2009)
Old 03-31-2009, 03:09 PM   #11 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Kalle View Post
If you want to generate PDF's in PHP, I would recommed to use Haru, instead of FPDF, its well documented on php.net and is better supported, plus its not only available as a PHP binding.

PHP Binding: http://pecl.php.net/haru
PHP Binding Documentation: http://www.php.net/haru
LibHaru: http://www.libharu.org/

Wow this looks great....looking at it now...

Do you know offhand if it supports flash images? I generate reports via flash graphs....
allworknoplay is offline  
Reply With Quote
Old 03-31-2009, 03:45 PM   #12 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

No I don't think Haru supports flash to be honest, but you can always add a feature request to their bug tracker and see if anyone can pick it up :)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Old 03-31-2009, 03:48 PM   #13 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Kalle View Post
No I don't think Haru supports flash to be honest, but you can always add a feature request to their bug tracker and see if anyone can pick it up :)
Darn!!!! I hate flash anyways, I've been trying to replace our flash graphs with regular PNG images but I haven't found any good freeware OR commercial products that gives me the current stellar quality of the flash graphs....


If Haru can do what I need it to do, then I'd rather look into replacing my flash graphs than to ask for a feature fix in Haru...although I guess it wouldn't hurt for Haru to continue multiple types of media objects....
allworknoplay is offline  
Reply With Quote
Old 03-31-2009, 03:56 PM   #14 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

Quote:
Originally Posted by allworknoplay View Post
Darn!!!! I hate flash anyways, I've been trying to replace our flash graphs with regular PNG images but I haven't found any good freeware OR commercial products that gives me the current stellar quality of the flash graphs....


If Haru can do what I need it to do, then I'd rather look into replacing my flash graphs than to ask for a feature fix in Haru...although I guess it wouldn't hurt for Haru to continue multiple types of media objects....
You could always try and see if ming or swf supports being converted to a static png, or atleast be able to read enough data to create a somewhat equal graph using GD or Imagick and then embed it in Haru.

But I have never worked with flash in php, so you are on your own there =)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Old 03-31-2009, 05:52 PM   #15 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Here's some of my code, maybe it helps:

PHP Code:
$pdf = new FPDF('P''mm''A4');
        
$pdf->AddPage();
        
$pdf->SetFont('Arial','B'16);
        
$pdf->Cell(4010'Some title');
        
$pdf->Cell(-40);
        
$pdf->SetFont('Arial',''12);
        
$pdf->Cell(040'Field: 14');
        
$pdf->Cell(-190);
        
$pdf->Cell(055'Field: xx');
        
$pdf->Cell(-190);
        
$pdf->Cell(070'Field: 22');
        
$pdf->Cell(-190);
        
$pdf->Output('file_name.pdf''D'); 
I hope you get the main idea. You practically add "blocks" on top of each other. Remember that an A4 page has 298mm x 210mm. Remember to add the line height to each line you add.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 04-01-2009, 02:36 AM   #16 (permalink)
The Acquainted
Inquisitive 
 
Join Date: Jul 2005
Location: UK
Posts: 121
Thanks: 41
Brook is on a distinguished road
Default

I was going to ask the same question so thanks for the topic!
__________________
PS3 Forums on GameSlurp - the site for gaming fans!
Brook is offline  
Reply With Quote
Old 04-01-2009, 12:14 PM   #17 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

Have not tried this but something similar words for .doc try

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
readfile('original.pdf');

Not to sure on the last line.

http://corymathews.com/?p=287 shows how to save for .doc but changing the header files to the ones about should save a page as a .pdf. Then you don't need any third party crap.
CoryMathews is offline  
Reply With Quote
Old 04-02-2009, 10:01 AM   #18 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

Quote:
Originally Posted by CoryMathews View Post
Have not tried this but something similar words for .doc try

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
readfile('original.pdf');

Not to sure on the last line.

http://corymathews.com/?p=287 shows how to save for .doc but changing the header files to the ones about should save a page as a .pdf. Then you don't need any third party crap.
What he wants is to generate a pdf on the fly, not send an already generated one to the user :)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Old 04-02-2009, 12:26 PM   #19 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

Ye that would generate one on the fly. It makes the normal .php page render as a .pdf page. So there is no need for third party apps to convert the page into pdf this header file will do that for him.

The .pdf file in the above example is not already created.
CoryMathews is offline  
Reply With Quote
Old 04-02-2009, 12:32 PM   #20 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

I think you misunderstand, he doesn't want to send the file to the browser, he wants to generate an actual pdf. Your example code sends the current page to the browser and forces it to not show it inline even if a plugin can display it inline.

And he does need "third party crap" to make a pdf, unless he wants to write a kick ass cryptic script to convert and write the binary data correct.
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Data output Sakakuchi Advanced PHP Programming 2 02-08-2009 02:26 PM
Save output from foreach into an array Sam Granger Absolute Beginners 2 01-15-2009 02:07 AM
Unexpected characters in output Killswitch Absolute Beginners 2 12-20-2008 04:29 AM
PHP Security: Escape Output nuweb General 4 11-24-2008 08:00 PM
Smarty output buffering? Aaron Libraries & Extensions 4 08-13-2008 09:35 AM


All times are GMT. The time now is 05:33 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design