[英]TCPDF Change Footer on last page
I am trying to create a pdf using TCPDF and need a different footer on the last page 我正在尝试使用TCPDF创建一个pdf,并在最后一页需要一个不同的页脚
using the following code I can get a different footer on the first page but not the last 使用下面的代码我可以在第一页上获得不同的页脚,但不是最后一页
I have looked at several post about this but can not make it work 我已经看过几篇关于此的帖子,但无法使其发挥作用
Any help implementing this would be much appreciated 任何帮助实现这一点将非常感激
public function Footer() {
$tpages = $this->getAliasNbPages();
$pages = $this->getPage();
$footer = 'NORMAL' . $pages . $tpages;
if ($pages == 1 ) $footer = 'FIRST' . $pages . $tpages;
if ($pages == $tpages) $footer = 'LAST' . $pages . $tpages;
$this->Cell(0, 10, $footer, 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
This gives me 这给了我
page1 - FIRST13 page 2 - NORMAL23 page 3 (Last Page) NORMAL23 第1页 - FIRST13第2页 - NORMAL23第3页(最后一页)NORMAL23
Answer: 回答:
public function Footer() {
$tpages = $this->getAliasNbPages();
$pages = $this->getPage();
$footer = 'NORMAL' . $pages . $tpages;
if ($pages == 1 ) $footer = 'FIRST' . $pages . $tpages;
if ($this->end == true) $footer = 'LAST' . $pages . $tpages;
$this->Cell(0, 10, $footer, 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
function display() {
#function that has main text
$this->AddPage();
$html = '1st page';
$this->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$this->AddPage();
$html = '2nd page';
$this->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$this->AddPage();
$html = 'Last page';
$this->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$this->end = true;
}
Your own answer does not answer your question to have a different footer on last page. 你自己的答案没有回答你的问题,在最后一页上有一个不同的页脚。
I found the following code from the author of tcPDF himself , which does exactly what you want. 我从tcPDF本人的作者那里找到了以下代码 ,它完全符合您的要求。
class mypdf extends tcpdf {
protected $last_page_flag = false;
public function Close() {
$this->last_page_flag = true;
parent::Close();
}
public function Footer() {
if ($this->last_page_flag) {
// ... footer for the last page ...
} else {
// ... footer for the normal page ...
}
}
}
Now that code works, but only if your last page differ. 现在该代码可以正常工作,但前提是您的最后一页不同。 In my case I could have 0-X last pages, so I still need to rely on a page counter. 在我的情况下,我可以有0-X的最后页面,所以我仍然需要依赖页面计数器。 This code works for me: 这段代码适合我:
class mypdf extends tcpdf {
public $page_counter = 1;
public function Make() {
...
// Create your own method for determining how many pages you got, excluding last pages
$this->page_counter = NUMBER;
...
}
public function Footer() {
if ($this->getPage() <= $this->page_counter) {
// ... footer for the normal page ...
} else {
// ... footer for the last page(s) ...
}
}
}
i hope this helps: 我希望这有帮助:
if($this->page == 1){
$this->Cell(0, 10, "ORIGINAL - Pagina '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
} else {
$this->Cell(0, 10, "COPY - Pagina '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
OR 要么
define("titulos_pie_pdf", ",ORIGINAL, COPY, TITLE1, TITLE2, ...", true);
then 然后
$titulos = explode(",",titulos_pie_pdf);
$this->Cell(0, 10, $titulos[$this->page]." - Pagina '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
i´m not a big programmer, but this code helps me. 我不是一个大程序员,但这段代码对我有帮助。
hi i had similar problem and this solved it: 嗨我有类似的问题,这解决了它:
public $isLastPage = false;
public function Footer()
{
if($this->isLastPage) {
$this->writeHTML($this->footer);
}
}
public function lastPage($resetmargins=false) {
$this->setPage($this->getNumPages(), $resetmargins);
$this->isLastPage = true;
}
hope it will help you :) its not exactly what you wanted but its easyli adjustable i think :) 希望它会帮助你:)它不完全是你想要的但它的easyli可调节我认为:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.