TCPDF - 仅在某些页面上有页脚/页眉 [英] TCPDF - Having footer/header on certain pages only

查看:39
本文介绍了TCPDF - 仅在某些页面上有页脚/页眉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文档的每一页上放置页脚部分,除了第一页.

I want to place the footer section on every page of my document except the first one.

我通过扩展 TCPDF 类并覆盖其页脚方法创建了我的自定义页脚.

I created my custom footer by extending the TCPDF class and overriding its footer method.

然后根据文档并使用以下示例,我明白我应该使用 SetPrintHeader 和 SetPrintFooter 方法:

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!

我在这里做错了什么?

提前一百万感谢!!

推荐答案

我认为

$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);   

您只是告诉 TCPDF 打印页眉和页脚(最后两个语句).

You are just telling TCPDF to print the header and footer (The last two statements).

您应该做的是,在页眉和页脚函数中,根据您所在的页面有条件地打印内容.类似于(未测试,我现在没有我的 PHP IDE)

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  

}

这篇关于TCPDF - 仅在某些页面上有页脚/页眉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆