Generate PDF with PHP
Moderator: General Moderators
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Generate PDF with PHP
How can I generate a pdf file with php?
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Generate PDF with PHP
Are those in the core php? Or should I download them?
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: Generate PDF with PHP
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.
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.
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Generate PDF with PHP
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.
And that this TCPDF is an extended version of FPDF.
Will try it, and give my opinion.
Thanks.
-
internet-solution
- Forum Contributor
- Posts: 220
- Joined: Thu May 27, 2010 6:27 am
- Location: UK
Re: Generate PDF with PHP
Other option is mPDF. It can generate PDF from HTML / css + UTF-8 supported. However, it can be very slow compared to FPDF.
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: Generate PDF with PHP
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.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.
Re: Generate PDF with PHP
I think TCPDF is good. TCP support UTF-8 Unicode, Xhtml, css
Here is a sample.
full sample herehttp://www.megaupload.com/?d=TDQV7W2A
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');