Question

in my footer code i would like to add a link that takes me back to the TOC (page 1), how can this be achieved?

 $backToTOC = $pdf->AddLink();

 class PDF extends FPDF
 {
    // Page header
    function Header()
    {
       // Logo
          $this->Image('newcoit_logo.jpg',70,10);
       // Arial bold 15
          $this->SetFont('Arial','B',15);
      // Move to the right
      // Line break
         $this->Ln(20);
    }

 // Page footer
 function Footer($backToTOC)
 {
   // Position at 1.5 cm from bottom
      $this->SetY(-15);
   // Arial italic 8
      $this->SetFont('Arial','I',8);
   // Page number
      $this->Cell(10,10,'Contact support: 1-800-newcoitsupport');
      $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
      $this->Cell(10,10,'Back to TOC',$backToTOC);
 }

}

on page 1:

 $pdf->SetLink($backToTOC);

the result of this is:

 PHP Notice:  Undefined variable: backToToc in /var/www/html/reporting/index.php on line 45

update: fixed case problem now error is:

 PHP Warning:  Missing argument 1 for PDF::Footer(), called in /var/www/lib/fpdf/fpdf.php on line 322 and defined in /var/www/html/reporting/index.php on line 23
Was it helpful?

Solution

FPDF calls the user implemented Footer() function like this :

// Page footer
$this->InFooter = true;
$this->Footer();
$this->InFooter = false;

You have defined the function like this :

function Footer($backToTOC) { 
}

Which demands the caller to pass a variable. Thats why you get the "Missing argument" warning. You do not have to pass $backToTOC since it (seems) to be defined already. Change the Footer function to

function Footer() {
  global $backToTOC;
  ...
}

BTW, perhaps you also need to set the link / $backToTOC to point at page 0.

$backToTOC = $pdf->AddLink();
$pdf->SetLink($backToTOC, -1, 0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top