FPDF - 通过删除页眉/页脚

时间:2018-01-24 03:42:27

标签: php html fpdf

我遇到了有关FPDF Header& amp;的问题。页脚,我想停止在PDF的最后一页创建页眉和页脚。我在页脚中使用了AliasNbPages()并且它有效,但它对Header不起作用,我认为这是因为它已经创建了#34;在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();

1 个答案:

答案 0 :(得分: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();

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