FPDF Header on First Page Only


We can make header using Header() method in FPDF. Header() method would show header content in all pages.We have to, use PageNo () in conditional statements to show header on first page only.

The following example shows, how to show header on first page only in FPDF.

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

  class PDF extends FPDF{
    
    function Header(){
      //Display Header Content, if page number eqaul 1
      if ($this->PageNo() == 1 ) {
        
        //Header Content
        $this->SetFont('Arial','B',15);
        $this->Cell(0,15,'HEADER TEXT',0,1,"C");
        $this->Line(0,30,210,30);
        $this->Ln();
      }
    }
  }

  $pdf=new PDF("P","mm","A4");
  $pdf->AddPage();
  $pdf->SetFont('Arial','',15);
  for($i=0;$i<35;$i++)
  {
    $pdf->Cell(0,15,"Line ".($i+1),0,1);
  }
  $pdf->Output();
?>
Output