title: FPDF: Decide when to set header/footer data
body: <p>I've been struggling with the header and footer data for quite some time now and thought it was time to ask it here on the forum. </p>
  
  <p>What I'm trying to do is decide that if a page is added if the header / footer should be added or not. so code-wise I want to set the header/footer to on or off when adding a page. </p>
  
  <p>I've tried to manipulate the function AddPage by setting an extra argument $setFooterHeader which default is set to true. And then trying to set this argument to false whenever I do an addPage('','',false); but it ignores it for some reason and I can't figure out why. </p>
  
  <p>If I set the default value of the argument to false in the function itself it works like a charm, but when I try to do it in my script and set it as an argument, it totally ignores it. </p>
  
  <p>Here's a code snippet of the fpdf.php file (function addPage) </p>
  
  <pre><code>function AddPage($orientation='', $size='', $setHeaderFooter=true) 
  { 
       // Start a new page 
       if($this-&gt;state==0) 
       $this-&gt;Open(); 
       $family = $this-&gt;FontFamily; 
       $style = $this-&gt;FontStyle.($this-&gt;underline ? 'U' : ''); 
       $fontsize = $this-&gt;FontSizePt; 
       $lw = $this-&gt;LineWidth; 
       $dc = $this-&gt;DrawColor; 
       $fc = $this-&gt;FillColor; 
       $tc = $this-&gt;TextColor; 
       $cf = $this-&gt;ColorFlag; 
       if($this-&gt;page&gt;0) 
       { 
           // Page footer 
           if ($setHeaderFooter == true) 
           { 
               $this-&gt;InFooter = true; 
               $this-&gt;Footer(); 
               $this-&gt;InFooter = false; 
               // Close page 
               $this-&gt;_endpage(); 
           } 
        } 
       // Start new page 
       $this-&gt;_beginpage($orientation,$size,$setHeaderFooter); 
       // Set line cap style to square 
       $this-&gt;_out('2 J'); 
       // Set line width 
       $this-&gt;LineWidth = $lw; 
       $this-&gt;_out(sprintf('%.2F w',$lw*$this-&gt;k)); 
       // Set font 
       if($family) 
       $this-&gt;SetFont($family,$style,$fontsize); 
       // Set colors 
       $this-&gt;DrawColor = $dc; 
       if($dc!='0 G') 
       $this-&gt;_out($dc); 
       $this-&gt;FillColor = $fc; 
       if($fc!='0 g') 
       $this-&gt;_out($fc); 
       $this-&gt;TextColor = $tc; 
       $this-&gt;ColorFlag = $cf; 
       // Page header 
       if ($setHeaderFooter == true) 
       { 
           $this-&gt;InHeader = true; 
           $this-&gt;Header(); 
           $this-&gt;InHeader = false; 
       } 
       // Restore line width 
       if($this-&gt;LineWidth!=$lw) 
       { 
           $this-&gt;LineWidth = $lw; 
           $this-&gt;_out(sprintf('%.2F w',$lw*$this-&gt;k)); 
       } 
       // Restore font 
       if($family) 
       $this-&gt;SetFont($family,$style,$fontsize); 
       // Restore colors 
       if($this-&gt;DrawColor!=$dc) 
       { 
           $this-&gt;DrawColor = $dc; 
           $this-&gt;_out($dc); 
       } 
       if($this-&gt;FillColor!=$fc) 
       { 
           $this-&gt;FillColor = $fc; 
           $this-&gt;_out($fc); 
       } 
       $this-&gt;TextColor = $tc; 
       $this-&gt;ColorFlag = $cf; 
  } 
  </code></pre>
  
  <p>Below is a code snippet of my PHP script which uses FPDF </p>
  
  <pre><code>/** PHP FPDF */ 
  require_once 'classes/FPDF/fpdf.php'; 
  require_once 'classes/FPDI/fpdi.php'; 
  
  class PDF extends FPDI 
  { 
       function Header() 
       { 
           $this-&gt;SetFont( 'Arial', 'B', 18 ); //set font to Arial, Bold, and 16 Size 
  
           //create heading with params 
           //0 - 100% width 
           //9 height 
           //"Page Heading" - With this text 
           //1 - border around it, and center aligned 
           //1 - Move pionter to new line after writing this heading 
           //'C' - center aligned 
           $this-&gt;Cell( 0, 9, 'Page Heading', 1, 1, 'C' ); 
  
           $this-&gt;ln( 5 ); 
       } 
  
       function Footer() 
       { 
           //move pionter at the bottom of the page 
           $this-&gt;SetY( -15 ); 
  
           //set font to Arial, Bold, size 10 
           $this-&gt;SetFont( 'Arial', 'B', 10 ); 
  
           //set font color to blue 
           $this-&gt;SetTextColor( 52, 98, 185 ); 
  
           $this-&gt;Cell( 0, 10, 'Footer Text', 0, 0, 'L' ); 
  
           //set font color to gray 
           $this-&gt;SetTextColor( 150, 150, 150 ); 
  
           //write Page No 
           $this-&gt;Cell( 0, 10, 'Page No: ' . $this-&gt;PageNo(), 0, 0, 'R' ); 
       } 
   } 
  
  // Create new PDF object 
  $pdf = new PDF('P','mm','A4'); 
  $pdf-&gt;addPage('','',false); 
  
  // Output pdf file 
  $pdf-&gt;Output('test.pdf','D'); 
  </code></pre>
  
  <p>Your help is greatly appreciated!!</p>