Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing or eliminating Header & Footer in TCPDF

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

like image 802
ChuckO Avatar asked Feb 07 '10 14:02

ChuckO


People also ask

Can a header be removed?

You can also delete a header from a single page. Go to Insert > Header or Footer, and then select Remove Header or Remove Footer.

How do I change the header in Excel?

On the Insert tab, in the Text group, click Header & Footer. Excel displays the worksheet in Page Layout view. To add or edit a header or footer, click the left, center, or right header or footer text box at the top or the bottom of the worksheet page (under Header, or above Footer).

How do you remove a header without affecting another page?

Click or tap where you want to start a new page without the header or footer. Go to Layout > Breaks > Next Page to create a section break. Double-click the header or footer area (near the top or bottom of the page) to open the Header & Footer tab. Select Link to Previous to turn off the link between the sections.


2 Answers

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(); 
like image 97
Brian Showalter Avatar answered Sep 27 '22 22:09

Brian Showalter


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.

like image 29
Lukey Avatar answered Sep 27 '22 23:09

Lukey