Minimal example

Let's start with the classical example:

<?php
require('fpdf.php');

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

After including the library file, we create an FPDF object. The FPDF() constructor is used here with the default values. Pages are in portrait and the measure unit is millimeter. It could have been specified explicitly with:

$pdf=new FPDF('P','mm');

It is possible to use landscape (L) and other measure units (pt, cm, in).

Open() starts the PDF document. There is still no page for the moment, so we have to add one with AddPage(). The origin is at the upper-left corner and the current position is by default placed at 1 cm from the borders; the margins can be changed with SetMargins().

Before we can print text, it is mandatory to select a font with SetFont(), otherwise the document would be invalid. We choose Arial bold 16:

$pdf->SetFont('Arial','B',16);

We could have specified italics with I or a font without style with an empty string. Note that the font size is given in points, not millimeters (or another user unit); it is the only exception. The other available fonts are Times, Courier, Symbol and ZapfDingbats.

We can now print a cell with Cell(). A cell is a rectangular area, possibly framed, which contains some text. It is output at the current position. We specify its dimensions, its text (centered or aligned), if it is framed and if the current position has to be moved to the right or return to the beginning of the next line. To add a frame, we would do this:

$pdf->Cell(40,10,'Hello World !',1);

To add a new cell next to it with centered text and go to the next line, we would do:

$pdf->Cell(60,10,'Powered by FPDF.',0,1,'C');

Remark : the line break can also be done with Ln(). This method allows to specify in addition the height of the break.

Finally, the document is closed and sent to the browser with Output(). We could have saved it in a file by passing the desired file name.