Tuesday, August 30, 2011

FPDF – Creating PDF files using PHP

SkyHi @ Tuesday, August 30, 2011
What is FPDF?

I came across thsi little gem while searching for a PHP class that allowed me to create PDFs on the fly using PHP. Basically, FPDF is a PHP class which generates PDF files using PHP. It is a free class and full documentation of its use and hw to use it can be found here.

With FPDF you can format a PDF in the same way that you would any PDF. There is support for header and footers, page breaks, images, colors and font-styling and page compression amongst other things.

FPDF works with PHP4 and PHP5.

The class is available for download from the FPDF site.

Once downloaded, put the class into site wherever you fancy and creating a PDF can be as simple as using the following code:

<?php

define('FPDF_FONTPATH','fpdf16/font/');

require('fpdf16/fpdf.php');
$pdf = new FPDF();

$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();

?>

REFERENCES
http://nick.boldison.com/websites/php/fpdf-creating-pdf-files-using-php/