Generate PDF with PHP
Posted: Fri Nov 26, 2010 3:56 am
How can I generate a pdf file with php?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
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.
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');