Convert PHP report to PDF for online printing

I want to take a dynamic summary report, which has been created in PHP, and output it as a PDF.  What is the best way to achieve this?  User-friendly, ideally.
ssailerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

g105bCommented:
The PDF functions in PHP can create PDF files using the PDFlib library which was initially created by Thomas Merz and is now maintained by PDFlib GmbH.

The below code shows how to construct basic PDF file from PHP.

If you don't have access to this library, or can't install it on your server, there is a free PHP class called FPDF that can be used to create server-side PDFs. This can be found at http://www.fpdf.org/

Take a look at the PHP docs about the inbuilt PDFlib - http://php.net/manual/en/book.pdf.php
<?php
$p = PDF_new();

/*  open new PDF file; insert a file name to create the PDF on disk */
if (PDF_begin_document($p, "", "") == 0) {
    die("Error: " . PDF_get_errmsg($p));
}

PDF_set_info($p, "Creator", "hello.php");
PDF_set_info($p, "Author", "Rainer Schaaf");
PDF_set_info($p, "Title", "Hello world (PHP)!");

PDF_begin_page_ext($p, 595, 842, "");

$font = PDF_load_font($p, "Helvetica-Bold", "winansi", "");

PDF_setfont($p, $font, 24.0);
PDF_set_text_pos($p, 50, 700);
PDF_show($p, "Hello world!");
PDF_continue_text($p, "(says PHP)");
PDF_end_page_ext($p, "");

PDF_end_document($p, "");

$buf = PDF_get_buffer($p);
$len = strlen($buf);

header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=hello.pdf");
print $buf;

PDF_delete($p);
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ssailerAuthor Commented:
Where, in this string of code, would I put my dynamic content?  I'm assuming I would be the recordset query at the top of the page?  Thanks.
0
g105bCommented:
You can use the PDF_show or PDF_continue_text functions to output content just like an echo does. There are plenty of examples in the php docs on http://php.net/manual/en/book.pdf.php
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.