Jay Jay - 11 months ago 68
PHP Question

FPDF Get page numbers at footer on Every A4 size page

I am creating PDF reports using FPDF. Now how do I generate page numbers on each page of a report at the bottom of the page.
Below is the sample code for generating a 2 page PDF.


$pdf = new FPDF();

$current_y = $pdf->GetY();
$current_x = $pdf->GetX();

$cell_width = 25; $cell_height=14;
$j = 20; // This value will be coming from Database so we dont know how many pages the report is going to be
for ($i = 0; $i<$j ; $i++){



Note : The $j value will be coming from the database so we don't know how many pages is the report going to be.

Answer Source

To add an A4 page, with portrait orientation, do:


Create a new class which extends the FPDF class, and override the pre-defined Footer method.


class PDF extends FPDF
    function Footer()
        // Go to 1.5 cm from bottom
        // Select Arial italic 8
        // Print centered page number
        $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');