Page 1 of 1

Generate PDF with PHP

Posted: Fri Nov 26, 2010 3:56 am
by klevis miho
How can I generate a pdf file with php?

Re: Generate PDF with PHP

Posted: Fri Nov 26, 2010 4:03 am
by greyhoundcode
Two options that come to mind are FPDF and PDFLib.

Re: Generate PDF with PHP

Posted: Fri Nov 26, 2010 4:04 am
by klevis miho
Are those in the core php? Or should I download them?

Re: Generate PDF with PHP

Posted: Fri Nov 26, 2010 4:21 am
by greyhoundcode
FPDF is a PHP class, so all you would need to do is download it and include/require it. PDFLib is an extension (its available on PECL I think) so unless it's already set up as part of your installation you'd need to install it.

Also, there is a free version of PDFLib but the main dish itself is commercial.

See the links in my first post for more info.

Re: Generate PDF with PHP

Posted: Fri Nov 26, 2010 4:23 am
by klevis miho
I found that Joomla has a TCPDF library in it's core installation (because I'm using joomla).
And that this TCPDF is an extended version of FPDF.

Will try it, and give my opinion.

Thanks.

Re: Generate PDF with PHP

Posted: Fri Nov 26, 2010 4:35 am
by internet-solution
Other option is mPDF. It can generate PDF from HTML / css + UTF-8 supported. However, it can be very slow compared to FPDF.

Re: Generate PDF with PHP

Posted: Fri Nov 26, 2010 2:20 pm
by greyhoundcode
internet-solution wrote:Other option is mPDF. It can generate PDF from HTML / css + UTF-8 supported. However, it can be very slow compared to FPDF.
I wasn't aware of that one, will need to check it out. Also, for the reference of anyone who is interested, another useful set of classes are found in the FPDI project, which extends FPDF so that existing PDF files can be loaded and edited.

Re: Generate PDF with PHP

Posted: Sat Nov 27, 2010 10:33 am
by tungt84
I think TCPDF is good. TCP support UTF-8 Unicode, Xhtml, css :D
Here is a sample.

Code: Select all

//Include lib
require_once('../config/lang/eng.php');
require_once('../tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 021');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
...................
// set font
$pdf->SetFont('helvetica', '', 9);

// add a page
$pdf->AddPage();

$html='some html content here';
//Write html content
$pdf->writeHTML($html, true, 0, true, 0);
...............................................
//Close and output PDF document
$pdf->Output('example_021.pdf', 'I');
full sample herehttp://www.megaupload.com/?d=TDQV7W2A