TCPDF自定义页码格式

时间:2012-08-22 06:58:32

标签: php pdf tcpdf

TCPDF中是否可以实现自定义页码格式?如果是,怎么样?

提前致谢。

2 个答案:

答案 0 :(得分:3)

$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().' of '.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');

您必须扩展TCPDF类,如下例所示:

 class MYPDF extends TCPDF {  
       // Page footer
        public function Footer() {
            // Position at 15 mm from bottom
            $this->SetY(-8);
            // Set font
            $this->SetFont('helvetica', 'I', 8);
            // Page number
          $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().' of '.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');     
        }      
    }


$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->AddPage();

答案 1 :(得分:0)

如果要更改TCPDF的工作方式,您需要覆盖页脚方法并实现自定义逻辑。

class CUSTOMPDF extends TCPDF {
  public function Footer() {

    $this->SetY(-10);
    $this->SetFont('verdana', 'N', 9);
    //more logic, take a look at the parent::Footer method

 }
}

通过调用$pdf = new CUSTOMPDF(<options>);

来使用它