Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:58:11+00:00 2026-05-30T22:58:11+00:00

I’ve been struggling with the header and footer data for quite some time now

  • 0

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.

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.

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.

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.

Here’s a code snippet of the fpdf.php file (function addPage)

function AddPage($orientation='', $size='', $setHeaderFooter=true) 
{ 
     // Start a new page 
     if($this->state==0) 
     $this->Open(); 
     $family = $this->FontFamily; 
     $style = $this->FontStyle.($this->underline ? 'U' : ''); 
     $fontsize = $this->FontSizePt; 
     $lw = $this->LineWidth; 
     $dc = $this->DrawColor; 
     $fc = $this->FillColor; 
     $tc = $this->TextColor; 
     $cf = $this->ColorFlag; 
     if($this->page>0) 
     { 
         // Page footer 
         if ($setHeaderFooter == true) 
         { 
             $this->InFooter = true; 
             $this->Footer(); 
             $this->InFooter = false; 
             // Close page 
             $this->_endpage(); 
         } 
      } 
     // Start new page 
     $this->_beginpage($orientation,$size,$setHeaderFooter); 
     // Set line cap style to square 
     $this->_out('2 J'); 
     // Set line width 
     $this->LineWidth = $lw; 
     $this->_out(sprintf('%.2F w',$lw*$this->k)); 
     // Set font 
     if($family) 
     $this->SetFont($family,$style,$fontsize); 
     // Set colors 
     $this->DrawColor = $dc; 
     if($dc!='0 G') 
     $this->_out($dc); 
     $this->FillColor = $fc; 
     if($fc!='0 g') 
     $this->_out($fc); 
     $this->TextColor = $tc; 
     $this->ColorFlag = $cf; 
     // Page header 
     if ($setHeaderFooter == true) 
     { 
         $this->InHeader = true; 
         $this->Header(); 
         $this->InHeader = false; 
     } 
     // Restore line width 
     if($this->LineWidth!=$lw) 
     { 
         $this->LineWidth = $lw; 
         $this->_out(sprintf('%.2F w',$lw*$this->k)); 
     } 
     // Restore font 
     if($family) 
     $this->SetFont($family,$style,$fontsize); 
     // Restore colors 
     if($this->DrawColor!=$dc) 
     { 
         $this->DrawColor = $dc; 
         $this->_out($dc); 
     } 
     if($this->FillColor!=$fc) 
     { 
         $this->FillColor = $fc; 
         $this->_out($fc); 
     } 
     $this->TextColor = $tc; 
     $this->ColorFlag = $cf; 
} 

Below is a code snippet of my PHP script which uses FPDF

/** PHP FPDF */ 
require_once 'classes/FPDF/fpdf.php'; 
require_once 'classes/FPDI/fpdi.php'; 

class PDF extends FPDI 
{ 
     function Header() 
     { 
         $this->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->Cell( 0, 9, 'Page Heading', 1, 1, 'C' ); 

         $this->ln( 5 ); 
     } 

     function Footer() 
     { 
         //move pionter at the bottom of the page 
         $this->SetY( -15 ); 

         //set font to Arial, Bold, size 10 
         $this->SetFont( 'Arial', 'B', 10 ); 

         //set font color to blue 
         $this->SetTextColor( 52, 98, 185 ); 

         $this->Cell( 0, 10, 'Footer Text', 0, 0, 'L' ); 

         //set font color to gray 
         $this->SetTextColor( 150, 150, 150 ); 

         //write Page No 
         $this->Cell( 0, 10, 'Page No: ' . $this->PageNo(), 0, 0, 'R' ); 
     } 
 } 

// Create new PDF object 
$pdf = new PDF('P','mm','A4'); 
$pdf->addPage('','',false); 

// Output pdf file 
$pdf->Output('test.pdf','D'); 

Your help is greatly appreciated!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:58:13+00:00Added an answer on May 30, 2026 at 10:58 pm

    I have solved this issue by setting a flag outside the class and use this flag in the header and footer function

    The fix is in the page section, not in the addPage function

    Just before doing an $pdf->addPage You set the flag as addPage automatically calls the header and footer function.

    Here’s the correct code (snippet of PHP script which uses FPDF)

    /** PHP FPDF */ 
    require_once 'classes/FPDF/fpdf.php'; 
    require_once 'classes/FPDI/fpdi.php'; 
    
    class PDF extends FPDI 
    { 
         function Header() 
         { 
            if ($this->header == 1)
            {
                $this->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->Cell( 0, 9, 'Page Heading', 1, 1, 'C' ); 
    
                $this->ln( 5 ); 
            }
         } 
    
         function Footer() 
         {
            if ($this->footer == 1)
            {
                 //move pionter at the bottom of the page 
                 $this->SetY( -15 ); 
    
                 //set font to Arial, Bold, size 10 
                 $this->SetFont( 'Arial', 'B', 10 ); 
    
                 //set font color to blue 
                 $this->SetTextColor( 52, 98, 185 ); 
    
                 $this->Cell( 0, 10, 'Footer Text', 0, 0, 'L' ); 
    
                 //set font color to gray 
                 $this->SetTextColor( 150, 150, 150 ); 
    
                 //write Page No 
                 $this->Cell( 0, 10, 'Page No: ' . $this->PageNo(), 0, 0, 'R' ); 
            }
         } 
     } 
    
    // Create new PDF object 
    $pdf = new PDF('P','mm','A4'); 
    
    $pdf->header = 0;
    $pdf->footer = 0;
    $pdf->addPage('','',false); 
    
    // Output pdf file 
    $pdf->Output('test.pdf','D'); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.