FPDF Tutorial for Beginners


FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs. click to download

Main Features


  • Page Format
  • Header and Footer
  • Automatic page break
  • Automatic line break
  • Adding Images (Supporting Image Format : JPEG, PNG, GIF)
  • Colors
  • Links

FPDF Constructor


This is the class constructor. It allows to set up the page size, the orientation and the unit of measure.

Parameters

  • Orientation
  • unit
  • Size

Orientation

Default value is P. other Values are

  • P or Portrait
  • L or Landscape
$pdf = new FPDF('P');

Unit

Default value is mm. font sizes are expressed in that unit. Other Values are

  • pt: point - equals 1/72 of inch
  • mm: millimetre - 1/72 of inch, equals to 0.35 mm
  • cm: centimetre - 1 inch being 2.54 cm
  • in: inch
$pdf = new FPDF('mm');

Size

Default value is A4. Other Values are

  • A3
  • A4
  • A5
  • Letter
  • Legal
$pdf = new FPDF('A4');

Source Code

<?php
	require_once "fpdf/fpdf.php"; //fpdf supporting file
 
	//Page Creation (Default value is P; Default value is mm; default page size: A4)
	#$pdf = new FPDF(); 
	//or
	$pdf = new FPDF('P','mm','A4');
 
 
	$pdf -> Output(); // Display output
?>
View Demo

Custom Page Size

Default value is A4. Other Values are

  • A3
  • A4
  • A5
  • Letter
  • Legal
$pdf = new FPDF('A4');

Source Code

<?php
	require_once "fpdf/fpdf.php"; //fpdf supporting file
 
	//Page Creation (Default value is P;Default value is mm;default page size: A4)
	#$pdf = new FPDF(); 
	//or
	$pdf = new FPDF('P','mm',array(100,150));
 
 
	$pdf -> Output(); // Display output
?>
View Demo