我正在尝试使用TCPDF创建一个pdf,并在最后一页需要一个不同的页脚
使用下面的代码我可以在第一页上获得不同的页脚,但不是最后一页
我已经看过几篇关于此的帖子,但无法使其发挥作用
任何帮助实现这一点将非常感激
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');
}
Run Code Online (Sandbox Code Playgroud)
这给了我
第1页 - FIRST13第2页 - NORMAL23第3页(最后一页)NORMAL23
回答:
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;
}
Run Code Online (Sandbox Code Playgroud)
Kim*_*Kim 12
你自己的答案没有回答你的问题,在最后一页上有一个不同的页脚.
我从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 ...
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在该代码可以正常工作,但前提是您的最后一页不同.在我的情况下,我可以有0-X的最后页面,所以我仍然需要依赖页面计数器.这段代码适合我:
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) ...
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10719 次 |
| 最近记录: |