更改或删除TCPDF中的页眉和页脚

Chu*_*ckO 36 php pdf-generation tcpdf

AddPage()在tcpdf中自动调用页眉和页脚.如何消除/覆盖这个?

Bri*_*ter 72

在调用之前使用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();
Run Code Online (Sandbox Code Playgroud)


Luk*_*key 11

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

  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, '');
        }
    }
Run Code Online (Sandbox Code Playgroud)

如果你更喜欢没有标题,你自然也可以使用它来返回任何内容.