title: FPDF table of contents and issues with page numbers
body: <p>basically, I'd like to start the Table of Contents (toc) on page 2 and count each page number of the toc. After the toc has ended I would like to start with the main content. These page should be numbered, too.</p>
  
  <p>In a nuthell:</p>
  
  <ul>
  <li>each page has to have a footer, except the cover page</li>
  <li>the first page which comes after the toc has to have the page number 4 instead of page number 1 (not like as in the example code below)</li>
  </ul>
  
  <p>Source (<a href="http://www.fpdf.org/en/script/script73.php" rel="nofollow">http://www.fpdf.org/en/script/script73.php</a>, filename is <em>toc.php</em>)</p>
  
  <pre><code>&lt;?php
  require('fpdf.php');
  
  class PDF_TOC extends FPDF {
      var $_toc=array();
      var $_numbering=false;
      var $_numberingFooter=false;
      var $_numPageNum=1;
  
      function AddPage($orientation='', $format='') {
          parent::AddPage($orientation,$format);
          if($this-&gt;_numbering)
              $this-&gt;_numPageNum++;
      }
  
      function startPageNums() {
          $this-&gt;_numbering=true;
          $this-&gt;_numberingFooter=true;
      }
  
      function stopPageNums() {
          $this-&gt;_numbering=false;
      }
  
      function numPageNo() {
          return $this-&gt;_numPageNum;
      }
  
      function TOC_Entry($txt, $level=0) {
          $this-&gt;_toc[]=array('t'=&gt;$txt,'l'=&gt;$level,'p'=&gt;$this-&gt;numPageNo());
      }
  
      function insertTOC( $location=1,
                          $labelSize=20,
                          $entrySize=10,
                          $tocfont='Times',
                          $label='Table of Contents'
                          ) {
          //make toc at end
          $this-&gt;stopPageNums();
          $this-&gt;AddPage();
          $tocstart=$this-&gt;page;
  
          $this-&gt;SetFont($tocfont,'B',$labelSize);
          $this-&gt;Cell(0,5,$label,0,1,'C');
          $this-&gt;Ln(10);
  
          foreach($this-&gt;_toc as $t) {
  
              //Offset
              $level=$t['l'];
              if($level&gt;0)
                  $this-&gt;Cell($level*8);
              $weight='';
              if($level==0)
                  $weight='B';
              $str=$t['t'];
              $this-&gt;SetFont($tocfont,$weight,$entrySize);
              $strsize=$this-&gt;GetStringWidth($str);
              $this-&gt;Cell($strsize+2,$this-&gt;FontSize+2,$str);
  
              //Filling dots
              $this-&gt;SetFont($tocfont,'',$entrySize);
              $PageCellSize=$this-&gt;GetStringWidth($t['p'])+2;
              $w=$this-&gt;w-$this-&gt;lMargin-$this-&gt;rMargin-$PageCellSize-($level*8)-($strsize+2);
              $nb=$w/$this-&gt;GetStringWidth('.');
              $dots=str_repeat('.',$nb);
              $this-&gt;Cell($w,$this-&gt;FontSize+2,$dots,0,0,'R');
  
              //Page number
              $this-&gt;Cell($PageCellSize,$this-&gt;FontSize+2,$t['p'],0,1,'R');
          }
  
          //Grab it and move to selected location
          $n=$this-&gt;page;
          $n_toc = $n - $tocstart + 1;
          $last = array();
  
          //store toc pages
          for($i = $tocstart;$i &lt;= $n;$i++)
              $last[]=$this-&gt;pages[$i];
  
          //move pages
          for($i=$tocstart-1;$i&gt;=$location-1;$i--)
              $this-&gt;pages[$i+$n_toc]=$this-&gt;pages[$i];
  
          //Put toc pages at insert point
          for($i = 0;$i &lt; $n_toc;$i++)
              $this-&gt;pages[$location + $i]=$last[$i];
      }
  
      function Footer() {
          if(!$this-&gt;_numberingFooter)
              return;
          //Go to 1.5 cm from bottom
          $this-&gt;SetY(-15);
          //Select Arial italic 8
          $this-&gt;SetFont('Arial','I',8);
          $this-&gt;Cell(0,7,$this-&gt;numPageNo(),0,0,'C'); 
          if(!$this-&gt;_numbering)
              $this-&gt;_numberingFooter=false;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Example</p>
  
  <pre><code>&lt;?php
  require('toc.php');
  
  $pdf= new PDF_TOC(); 
  $pdf-&gt;SetFont('Times','',12);
  $pdf-&gt;AddPage();
  $pdf-&gt;Cell(0,5,'Cover',0,1,'C');
  $pdf-&gt;AddPage();
  $pdf-&gt;startPageNums();
  $pdf-&gt;Cell(0,5,'TOC1',0,1,'L');
  $pdf-&gt;TOC_Entry('TOC1', 0);
  $pdf-&gt;Cell(0,5,'TOC1.1',0,1,'L');
  $pdf-&gt;TOC_Entry('TOC1.1', 1);
  $pdf-&gt;AddPage();
  $pdf-&gt;Cell(0,5,'TOC2',0,1,'L');
  $pdf-&gt;TOC_Entry('TOC2', 0);
  $pdf-&gt;AddPage();
  for($i=3;$i&lt;=80;$i++){
      $pdf-&gt;Cell(0,5,'TOC'.$i,0,1,'L');
      $pdf-&gt;TOC_Entry('TOC'.$i, 0);
  }
  $pdf-&gt;stopPageNums();
  //Generate and insert TOC at page 2
  $pdf-&gt;insertTOC(2);
  $pdf-&gt;Output();
  ?&gt;
  </code></pre>
  
  <p>How can I do this? I can clarify the question/code if needed. I would appreciate any help to resolve my issue. Thanks in advance.</p>