TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Output to PDF (http://www.talkphp.com/advanced-php-programming/4084-output-pdf.html)

allworknoplay 03-30-2009 02:42 PM

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???

Village Idiot 03-30-2009 05:55 PM

So what exactly is your question?

allworknoplay 03-30-2009 08:31 PM

Quote:

Originally Posted by Village Idiot (Post 22595)
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....

Village Idiot 03-30-2009 09:19 PM

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

allworknoplay 03-30-2009 09:28 PM

Quote:

Originally Posted by Village Idiot (Post 22598)
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....

Andrial12 03-30-2009 10:50 PM

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.

allworknoplay 03-30-2009 11:09 PM

Quote:

Originally Posted by Andrial12 (Post 22601)
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....

Enfernikus 03-31-2009 12:21 AM

http://www.digitaljunkies.ca/dompdf/

allworknoplay 03-31-2009 02:18 AM

Quote:

Originally Posted by Enfernikus (Post 22603)


Thanks I will take a look.....

Kalle 03-31-2009 07:27 AM

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/

allworknoplay 03-31-2009 03:09 PM

Quote:

Originally Posted by Kalle (Post 22607)
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....

Kalle 03-31-2009 03:45 PM

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 :)

allworknoplay 03-31-2009 03:48 PM

Quote:

Originally Posted by Kalle (Post 22609)
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....

Kalle 03-31-2009 03:56 PM

Quote:

Originally Posted by allworknoplay (Post 22610)
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 =)

xenon 03-31-2009 05:52 PM

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.

Brook 04-01-2009 02:36 AM

I was going to ask the same question so thanks for the topic!

CoryMathews 04-01-2009 12:14 PM

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.

Kalle 04-02-2009 10:01 AM

Quote:

Originally Posted by CoryMathews (Post 22634)
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 :)

CoryMathews 04-02-2009 12:26 PM

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.

Kalle 04-02-2009 12:32 PM

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.


All times are GMT. The time now is 01:10 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0