37

AddPage() in tcpdf automatically calls Header and Footer. How do I eliminate/override this?

Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116
ChuckO
  • 2,543
  • 6
  • 34
  • 41

6 Answers6

76

Use the SetPrintHeader(false) and SetPrintFooter(false) methods before calling AddPage(). Like this:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, 'LETTER', true, 'UTF-8', false);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116
Brian Showalter
  • 4,321
  • 2
  • 26
  • 29
  • This answer didn't really help me for what I wanted to do. I wanted **only the first page** to have no headers or footers... THIS http://queirozf.com/reminders/tcpdf-how-to-print-a-page-with-no-header-or-footer is what I did in the end. – Felipe Aug 29 '12 at 19:42
13

A nice easy way to have control over when to show the header - or bits of the header - is by extending the TCPDF class and creating your own header function like so:

  class YourPDF extends TCPDF {
        public function Header() {
            if (count($this->pages) === 1) { // Do this only on the first page
                $html .= '<p>Your header here</p>';
            }

            $this->writeHTML($html, true, false, false, false, '');
        }
    }

Naturally you can use this to return no content as well, if you'd prefer to have no header at all.

Lukey
  • 922
  • 1
  • 7
  • 9
2

Here is an alternative way you can remove the Header and Footer:

// Remove the default header and footer
class PDF extends TCPDF { 
    public function Header() { 
    // No Header 
    } 
    public function Footer() { 
    // No Footer 
    } 
} 

$pdf = new PDF();
zeddex
  • 1,260
  • 5
  • 21
  • 38
1

Example:
- First page, no footer
- Second page, has footer, start with page no 1

Structure:

    // First page
    $pdf->startPageGroup();
    $pdf->setPrintFooter(false);

    $pdf->addPage();
    // ... add page content here
    $pdf->endPage();

    // Second page
    $pdf->startPageGroup();
    $pdf->setPrintFooter(true);

    $pdf->addPage();
    // ... add page content here
    $pdf->endPage();
Nik
  • 418
  • 4
  • 10
1

How do I eliminate/override this?

Also, Example 3 in the TCPDF docs shows how to override the header and footer with your own class.

Nathan
  • 3,842
  • 1
  • 26
  • 31
0
// set default header data
$pdf->SetHeaderData('', PDF_HEADER_LOGO_WIDTH, 'marks', 'header string');

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

With the help of above functions you can change header and footer.

j0k
  • 22,600
  • 28
  • 79
  • 90
Kracekumar
  • 19,457
  • 10
  • 47
  • 56
  • 1
    Thanks for your belated answer. I had wanted to eliminate the Header/Footer, and Brian's way did it. – ChuckO Oct 15 '10 at 12:30