FPDF - Header and Footer

We can make header and footer using Header() and Footer() methods. They already present in FPDF class but have no definition, therefore we have to extend the class and override them.


  class PDF extends FPDF
    //Page Header
    function Header(){
      $this->Cell(0,15,'Sample Header',0,1,'C');
      // Line Break
    //Page Header
    function Footer(){
      // Position at 15 mm from bottom
      // set page number and total number of pages
      $this->Cell(0,15,'Page No : '.$this->PageNo()." / {nb}",0,1,'C');
  //Create object of inherited class
  $pdf=new PDF();
  //Call this function for special value {nb} (total number of pages) 
    $pdf->Cell(0,15,"Line ".($i+1),0,1);