Search code examples
fpdf

FPDF PHP using SetY footer displays on next page


When using SetY in FPDF the content seems to not be placed based on the bottom of a page. I've tried using their example of a footer:

class PDF extends FPDF
{


// Page footer
function Footer()
{
    // Position at 1.5 cm from bottom
    $this->SetY(-15);
    // Arial italic 8
    $this->SetFont('Arial','I',8);
    // Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}

And also just placing it at the end of my page:

//Regular page content
$pdf->Cell(40,10,'Apple and iPhone are trademarks of Apple Inc., registered in the U.S. and other countries.');

//Footer content
$pdf->SetY(-15);
// Arial italic 8
$pdf->SetFont('Arial','I',8);
// Page number
$pdf->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

$pdf->Output();

But both seem to be relative to the content that is already loaded on the pdf page, not based on the bottom of the page. If the content of the page is 40 lines, the footer content will load on the same page. If the content of the page is 100 lines, the footer content is displayed at the top of a new page.

Any input is appreciated.


Solution

  • Try setting the Y to be positive. ex: $pdf->SetY(240); It wil set the position realtive to the top of the page.