【问题标题】:Custom Page Number in TCPDFTCPDF 中的自定义页码
【发布时间】:2019-04-04 19:11:34
【问题描述】:

我正在使用 TCPDF 来生成我的 pdf。我不知道重置起始页码。我的意思是,我将生成报告,在页脚中开始第 3 页(不是 1),但第二页增加 2(3、5、6、7 等)

这是我的代码:

$_SESSION["hal"] = $_POST["hal"];
$_SESSION["f"] = $_POST["f"];


class MYPDF extends TCPDF {

    // Page footer
    public function Footer() {

        // Position at 25 mm from bottom
        $this->SetY(-25);
        // Set font

        $this->SetFont('helvetica', 'b', 8);

        // Page number

        $this->Cell(0, 15,$_SESSION["f"]." ". $_SESSION["hal"], 'T', false, 'R', 0, '', 0, false, 'T', 'M');
                $_SESSION["hal"]++;
    }
}

有人可以帮忙吗..

【问题讨论】:

    标签: tcpdf


    【解决方案1】:

    完成..

    $_SESSION["hal"] = $_POST["hal"]; $_SESSION["f"] = $_POST["f"];

    MYPDF 类扩展 TCPDF {

    // Page footer
    public function Footer() {
    
        // Position at 25 mm from bottom
        $this->SetY(-25);
        // Set font
    
        $this->SetFont('helvetica', 'b', 8);
    
        // Page number
        //i add var to store current page
        $halaman = $this->PageNo();
        $this->Cell(0, 15,$_SESSION["f"]." ". ($halaman+$_SESSION["hal"]), 'T', false, 'R', 0, '', 0, false, 'T', 'M');
    
    }
    

    }

    【讨论】:

      【解决方案2】:

      另一种方法是使用页面组。不需要 SESSION 就更好了。

      要启动组:

      $this->startPageGroup();
      

      并打印:

      $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';
      if (empty($this->pagegroups)) {
         $pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
      } else {
      $pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
      $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-26
        • 1970-01-01
        • 1970-01-01
        • 2020-02-28
        • 2015-02-27
        • 2021-11-27
        • 1970-01-01
        相关资源
        最近更新 更多