FPDF – Creating PDF files using PHP

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
require('fpdf.php');

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

Full documentation on how to use FPDF can be found on the main site at: http://www.fpdf.org/

Try it, you might like it :)

  • http://danhoward.co.uk Dan

    Or you could use the Zend Framework, and the built-in Zend_Pdf ;)

  • http://eggchops.com eggChops

    Yeah I could have done that if it weren’t using our 9xb template ;)
    It’ll be another few years before we start using stuff like that :(

  • http://www.roughedge.se Andreas

    You could use the Zend framework but i rather not have the memory footprint of doooooom.