修改或消除TCPDF中的页眉和页脚

时间:2021-07-27 21:11:23

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

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

5 个解决方案

#1


70  

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

在调用AddPage()之前使用SetPrintHeader(false)和SetPrintFooter(false)方法。喜欢这个:

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

#2


11  

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:

控制何时显示标题 - 或标题位 - 的一个很好的简单方法是扩展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, '');
        }
    }

Naturally you can use this to return no content as well, if you'd prefer to have no header at all.

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

#3


2  

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

#4


1  

How do I eliminate/override this?

如何消除/覆盖这个?

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

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

#5


0  

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

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

#1


70  

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

在调用AddPage()之前使用SetPrintHeader(false)和SetPrintFooter(false)方法。喜欢这个:

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

#2


11  

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:

控制何时显示标题 - 或标题位 - 的一个很好的简单方法是扩展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, '');
        }
    }

Naturally you can use this to return no content as well, if you'd prefer to have no header at all.

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

#3


2  

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

#4


1  

How do I eliminate/override this?

如何消除/覆盖这个?

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

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

#5


0  

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

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