php 更改或消除 TCPDF 中的页眉和页脚

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2217132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:33:57  来源:igfitidea点击:

Changing or eliminating Header & Footer in TCPDF

phppdf-generationtcpdf

提问by ChuckO

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

AddPage()在 tcpdf 中自动调用页眉和页脚。我如何消除/覆盖它?

回答by Brian Showalter

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

在调用 之前使用SetPrintHeader(false)SetPrintFooter(false)方法AddPage()。像这样:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, 'LETTER', true, 'UTF-8', false);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();

回答by Lukey

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:

控制何时显示标题 - 或标题的位 - 的一个很好的简单方法是扩展 TCPPDF 类并创建自己的标题函数,如下所示:

  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.

当然,如果您希望根本没有标题,您也可以使用它来不返回任何内容。

回答by zeddex

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

回答by Nathan

How do I eliminate/override this?

我如何消除/覆盖它?

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

此外,TCPDF 文档中的示例 3显示了如何使用您自己的类覆盖页眉和页脚。

回答by Kracekumar

// 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.

借助上述功能,您可以更改页眉和页脚。

回答by Nik

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

示例:
- 第一页,无页脚
- 第二页,有页脚,从第 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();