Reputation: 123
I want to place the footer section on every page of my document except the first one.
I created my custom footer by extending the TCPDF class and overriding its footer method.
Then based on the documentation and using below example I understand I should use SetPrintHeader and SetPrintFooter methods:
http://www.tcpdf.org/examples/example_002.phps
// Page one
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
// Page two and on ..
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(true);
$pdf->AddPage();
However, the above does not prevent the footer/header from being printed at all!
What am i doing wrong here ?
Thanks a million in advance !!
Upvotes: 5
Views: 20703
Reputation: 81
Header can be controlled by modifying the function startPage in tcpdf.php
In this example, I need headers from page 2 only.
// print page header
if ($this->numpages > 1) {
$this->setHeader();
}
Upvotes: 1
Reputation: 76870
I think that
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
prints or hides the header and footer globally so if you do
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
// Page two and on ..
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(true);
You are just telling TCPDF to print the header and footer (The last two statements).
What you should do is, in the header and footer function, print things conditionally based on the page you are in. Something like (not tested, i haven't my PHP IDE right now)
function Header(){
$pageN = PageNo();
if($pageN % 2 === 0){
//if page is 2/4/6... don't print anything
return;
}else{
//do your stuff
}
Upvotes: 8