如何使用 tcpdf 编辑页脚?我想在页脚添加当前日期和时间。请帮忙。
问问题
38112 次
7 回答
21
像这样覆盖类:
class MYPDF extends TCPDF {
public function Footer() {
$image_file = "img/bg_bottom_releve.jpg";
$this->Image($image_file, 11, 241, 189, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->SetY(-15);
$this->SetFont('helvetica', 'N', 6);
$this->Cell(0, 5, date("m/d/Y H\hi:s"), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
然后而不是调用:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
做 :
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
于 2012-01-18T15:34:05.530 回答
6
您必须扩展 TCPDF 类并覆盖 Footer() 方法,如默认示例 n 中所述。3. 查看官方http://www.tcpdf.org网站和论坛了解更多信息。
于 2010-08-06T11:06:49.567 回答
3
请问如何创建 2 个页脚行?
class MYPDF extends TCPDF {
private $customFooterText = "";
/**
* @param string $customFooterText
*/
public function setCustomFooterText($customFooterText)
{
$this->customFooterText = $customFooterText;
}
public function Footer()
{
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 10, $this->customFooterText, 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
用法
$pdf = new MYPDF();
$pdf->setCustomFooterText('THIS IS CUSTOM FOOTER');
于 2019-05-16T20:06:08.657 回答
0
在EOD之后,使用下面的代码覆盖页脚方法。
EOD;
$txt = date("m/d/Y h:m:s");
// print a block of text using Write()
$pdf->Write($h=0, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);
于 2010-06-01T11:38:29.500 回答
0
如果您想在多个页面上放置不同的内容:
define("bottom_info", "|FIRST PAGE|SECOND PAGE|THIRD PAGE|...", true);
信息将由“|”分隔(具有爆炸功能)
班级:
class MYPDF extends TCPDF {
public function Header() {
}
// Page footer
public function Footer() {
$this->SetY(-15);
$this->SetFont('helvetica', '', 7);
// Page number
$titulos = explode("|",bottom_info);
$this->Cell(0, 10, $titulos[$this->page].' - Pagina '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
于 2015-03-06T20:09:16.917 回答
0
如果您想动态更改页脚文本,则像这样扩展 TCPDF
class MYPDF extends TCPDF {
private $customFooterText = "";
/**
* @param string $customFooterText
*/
public function setCustomFooterText($customFooterText)
{
$this->customFooterText = $customFooterText;
}
public function Footer()
{
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 10, $this->customFooterText, 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
用法:
$pdf = new MYPDF();
$pdf->setCustomFooterText('THIS IS CUSTOM FOOTER');
// .... etc
于 2019-02-08T08:40:53.500 回答
-1
我想通了,这是可能遇到此线程的其他人的解决方案。
编辑文件“tcpdf.php”。
搜索“ public function Footer()
”
在此处添加时间戳:
$timestamp = date("m/d/Y h:m:s");
if (empty($this->pagegroups)) {
$pagenumtxt = ' Created on ' .$timestamp.' '.$this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
} else {
$pagenumtxt = ' Created on ' .$timestamp.' '. $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
}
于 2010-06-04T18:29:36.390 回答