TCPDF Change Footer on last page

折月煮酒 提交于 2019-12-06 01:40:21

Your own answer does not answer your question to have a different footer on last page.
I found the following code from the author of tcPDF himself, which does exactly what you want.

class mypdf extends tcpdf {

  protected $last_page_flag = false;

  public function Close() {
    $this->last_page_flag = true;
    parent::Close();
  }

  public function Footer() {
    if ($this->last_page_flag) {
      // ... footer for the last page ...
    } else {
      // ... footer for the normal page ...
    }
  }
}

Now that code works, but only if your last page differ. In my case I could have 0-X last pages, so I still need to rely on a page counter. This code works for me:

class mypdf extends tcpdf {

  public $page_counter = 1;

  public function Make() {
    ...

    // Create your own method for determining how many pages you got, excluding last pages
    $this->page_counter = NUMBER;

    ...
  }

  public function Footer() {
    if ($this->getPage() <= $this->page_counter) {
      // ... footer for the normal page ...
    } else {
      // ... footer for the last page(s) ...
    }
  }
}

i hope this helps:

    if($this->page == 1){
        $this->Cell(0, 10, "ORIGINAL - Pagina '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    } else {
        $this->Cell(0, 10, "COPY - Pagina '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }

OR

define("titulos_pie_pdf", ",ORIGINAL, COPY, TITLE1, TITLE2, ...", true);    

then

    $titulos = explode(",",titulos_pie_pdf);
    $this->Cell(0, 10, $titulos[$this->page]." - Pagina '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');

i´m not a big programmer, but this code helps me.

hi i had similar problem and this solved it:

public $isLastPage = false;

public function Footer()
{
    if($this->isLastPage) {    
      $this->writeHTML($this->footer);
    }
}

public function lastPage($resetmargins=false) {
    $this->setPage($this->getNumPages(), $resetmargins);
    $this->isLastPage = true;
}

hope it will help you :) its not exactly what you wanted but its easyli adjustable i think :)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!