How to generate pdf in PHP using FPDF

FPDF is php class that is used to generate pdf in php. IN FPDF F stands for free it means you can use or modify it accordingly.

Features :

  1. Header & Footer management
  2. Line break option
  3. Image support
  4. Links
  5. Colors

Example :

Simple Pdf


<?php
require('fpdf.php');
$aPdf = new FPDF();
$aPdf->AddPage();
$aPdf->SetFont('Arial','B',20);
$aPdf->Cell(100,100,'Welcome to Code Execute');
$aPdf->Output();
?>

 

Pdf with Header and Footer


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

class cePdf extends FPDF
{
	// Page header
	function Header()
	{
	    $this->SetFont('Arial','B',40);
	    $this->Cell(80);
	    $this->Cell(30,10,'Logo',0,0,'C');
	    $this->Ln(20);
	}

	// Page footer
	function Footer()
	{
	    $this->SetY(-15);
	    $this->SetFont('Arial','',10);
	    $this->Cell(0,10,'This is footer',0,0,'C');
	}
}

$aPdf = new cePdf();
$aPdf->AddPage();
$aPdf->SetFont('Arial','',15);
$aPdf->Cell(0,30,'Welcome to Code Execute',0,0,'L');
$aPdf->Output();
?>

Download Fpdf