TCPDF - Having footer/header on certain pages only

懵懂的女人 提交于 2019-12-05 12:52:27

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  

}

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();
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!