TCPDF编辑页脚

问题描述 投票:8回答:7

如何使用TCPDF编辑页脚?我想在页脚中添加当前的日期和时间。请帮忙。

edit footer tcpdf
7个回答
19
投票

覆盖这样的类:

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);

6
投票

你必须扩展TCPDF类并覆盖页脚()方法,作为在默认例如正说明。 3.检查官方http://www.tcpdf.org网站和论坛了解更多信息。


2
投票

如何创建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');

0
投票

排爆后,使用下面的代码覆盖页脚方法。

 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);

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');
}

}


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 

-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();

}
© www.soinside.com 2019 - 2024. All rights reserved.