【问题标题】:FPDF - creating blank/white page at last page by remove Header / FooterFPDF - 通过删除页眉/页脚在最后一页创建空白/白页
【发布时间】:2018-01-24 03:42:26
【问题描述】:

我遇到了关于 FPDF 页眉和页脚的问题,我想停止在 PDF 的最后一页创建页眉和页脚。我在页脚使用了 AliasNbPages() 并且它有效,但它对 Header 不起作用,我认为这是因为它在 AliasNbPages() 能够将总页面传递到 Header 之前已经“创建”。是否有任何可能的方法将总页(也是最后一页)传递到页眉并从最后一页排除页眉?谢谢。

class PDF extends FPDF
{
function Header()
{
if($this->PageNo() != '{nb}')
{
//My header codes
}
}

function Footer()
{
global $totalPageForFooter;
if($this->PageNo() != $totalPageForFooter){

//My footer codes
}   
}
}
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();

$totalPageForFooter = $pdf->PageNo();
$pdf->Output();

【问题讨论】:

    标签: php html fpdf


    【解决方案1】:

    我找到了解决方案,方法很简单,而不是在标题中使用 {nb}。

    class PDF extends FPDF
    {
    function Header()
    {
    global $headerVisible;
    if($headerVisible=="true")
    {
    //My header codes
    }
    }
    
    function Footer()
    {
    global $totalPageForFooter;
    if($this->PageNo() != $totalPageForFooter){
    
    //My footer codes
    }   
    }
    }
    $pdf = new PDF();
    $pdf->AliasNbPages();
    $headerVisible="true";
    $pdf->AddPage();
    //body coding goes here
    $headerVisible="false"; // After the body coding finish execute, we have to clear the header first before AddPage(), if not, the $headerVisible will not valid until next header.
    $pdf->AddPage(); // this one is the last empty page i wish to make it blank
    $totalPageForFooter = $pdf->PageNo();
    $pdf->Output();
    

    我希望我在解释这个时没有错,希望它可以帮助那些需要这个的人。谢谢。

    【讨论】:

    • 这很简单,似乎工作正常。感谢您在找到解决方案后发布解决方案。
    猜你喜欢
    • 2018-07-06
    • 1970-01-01
    • 2022-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 2010-10-30
    相关资源
    最近更新 更多