【问题标题】:TCPDF: Get total number of pages / find out if it's the last pageTCPDF:获取总页数/找出它是否是最后一页
【发布时间】:2012-02-25 03:32:13
【问题描述】:

我不想在我的 PDF 的第一页和最后一页上显示页码,因此在我的自定义页脚功能中,我试图将当前页码与总页数进行比较,因为 $this 后该页码不起作用->getAliasNbPages();返回一个无法转换为整数的字符串(类似于 "{ptp)"}。

如何以整数形式获取总页数或以其他方式找出当前页是否为最后一页?

【问题讨论】:

    标签: tcpdf


    【解决方案1】:

    你可以使用

    $this->getNumPages();
    

    【讨论】:

      【解决方案2】:
      /**
       * Reset pointer to the last document page.
       * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
       * @public
       * @since 2.0.000 (2008-01-04)
       * @see setPage(), getPage(), getNumPages()
       */
                 public function lastPage($resetmargins=false) {
                    $this->setPage($this->getNumPages(), $resetmargins);
                 }
      
      
      /**
       * Get current document page number.
       * @return int page number
       * @public
       * @since 2.1.000 (2008-01-07)
       * @see setPage(), lastpage(), getNumPages()
       */
                 public function getPage() {
                    return $this->page;
                 }
      
      /**
       * Get the total number of insered pages.
       * @return int number of pages
       * @public
       * @since 2.1.000 (2008-01-07)
       * @see setPage(), getPage(), lastpage()
       */
                 public function getNumPages() {
                    return $this->numpages;
                 }
      

      最初来自 tcpdf.php 你可以在那里找到它

      【讨论】:

      • 我无法弄清楚这些函数如何让您识别当前页面是否为最后一页。 PageNo() 会告诉你当前的页码,但它总是等于从getNumPages()返回的值
      • 对不起,我已经多年没有解决这个问题了,完全忘记了我是怎么做到的,我敢打赌你在同一个循环中调用 getNumPagespageNo,这就解释了为什么你得到相同的数字,.. 我知道这很愚蠢,但尝试做一个模拟,run dummyLoop(){}; $allpages=getNumPages of dummyLoop; run actualLoop(){if(pageNo()==$allpages){echo"you're in the last page mate!";}} 或类似的东西
      猜你喜欢
      • 2012-05-28
      • 2012-04-16
      • 2014-03-13
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-04
      • 2021-02-05
      相关资源
      最近更新 更多