 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
03-30-2009, 02:42 PM
|
#1 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
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???
|
|
|
|
03-30-2009, 05:55 PM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
So what exactly is your question?
|
|
|
|
03-30-2009, 08:31 PM
|
#3 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Village Idiot
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....
|
|
|
|
03-30-2009, 09:28 PM
|
#5 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Village Idiot
|
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....
|
|
|
|
03-30-2009, 10:50 PM
|
#6 (permalink)
|
|
The Wanderer
Join Date: Feb 2008
Location: Blackpool, England
Posts: 16
Thanks: 2
|
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.
|
|
|
|
03-30-2009, 11:09 PM
|
#7 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Andrial12
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....
|
|
|
|
03-31-2009, 12:21 AM
|
#8 (permalink)
|
|
The Addict
Join Date: Jun 2008
Posts: 335
Thanks: 2
|
|
|
|
|
|
The Following User Says Thank You to Enfernikus For This Useful Post:
|
|
03-31-2009, 02:18 AM
|
#9 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Enfernikus
|
Thanks I will take a look.....
|
|
|
|
03-31-2009, 07:27 AM
|
#10 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
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/
__________________
|
|
|
|
The Following User Says Thank You to Kalle For This Useful Post:
|
|
03-31-2009, 03:09 PM
|
#11 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Kalle
|
Wow this looks great....looking at it now...
Do you know offhand if it supports flash images? I generate reports via flash graphs....
|
|
|
|
03-31-2009, 03:45 PM
|
#12 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
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 :)
__________________
|
|
|
03-31-2009, 03:48 PM
|
#13 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Kalle
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....
|
|
|
|
03-31-2009, 03:56 PM
|
#14 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
Quote:
Originally Posted by allworknoplay
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 =)
__________________
|
|
|
03-31-2009, 05:52 PM
|
#15 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
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(40, 10, 'Some title'); $pdf->Cell(-40); $pdf->SetFont('Arial','', 12); $pdf->Cell(0, 40, 'Field: 14'); $pdf->Cell(-190); $pdf->Cell(0, 55, 'Field: xx'); $pdf->Cell(-190); $pdf->Cell(0, 70, '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.
|
|
|
|
04-01-2009, 02:36 AM
|
#16 (permalink)
|
|
The Acquainted
Join Date: Jul 2005
Location: UK
Posts: 121
Thanks: 41
|
I was going to ask the same question so thanks for the topic!
__________________
PS3 Forums on GameSlurp - the site for gaming fans!
|
|
|
|
04-01-2009, 12:14 PM
|
#17 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
|
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.
|
|
|
|
04-02-2009, 10:01 AM
|
#18 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
Quote:
Originally Posted by CoryMathews
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 :)
__________________
|
|
|
04-02-2009, 12:26 PM
|
#19 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
|
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.
|
|
|
|
04-02-2009, 12:32 PM
|
#20 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
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.
__________________
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|