John
John

Reputation: 7067

TCPDF getAliasNbPages - Get total pages of produced file

I'm using the follwing TCPDF code to generate PDFs with the writeHTML function. I have the page number footer function which puts page numbers at the bottom of each page as the pdf total pages grows. I'm trying to find a way at the end of creating all the pages to determine how many total pages the produced document has so that i can store that information into a variable and submit that data to a DB.

I've tried:

$total = $pdf->getAliasNbPages();

but doesnt work, Any ideas?

Thanks

// PAGE NUMBERED FOOTER

class MYPDF extends TCPDF {

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
    $this->SetFont('Calibri', '', 8);
        // Page number

    $pageNumbers = 'Page '.$this->getAliasNumPage().' of '.$this->getAliasNbPages();

        $this->Cell(0, 10, $pageNumbers, 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }

}


$html = 'html content';

$pdf->writeHTML($html, true, false, true, false, '');

$pdf->Output('file.pdf', 'I');

Upvotes: 2

Views: 9432

Answers (3)

Patrizio Onorati
Patrizio Onorati

Reputation: 71

$pdf->Cell(0, 10,'{:ptp:}', 0, false, 'C', 0, '', 0, false, 'T', 'M');

Upvotes: 1

Rafik Haceb
Rafik Haceb

Reputation: 153

To get the total number of pages, use $this->getAliasNbPages() as chown in this example https://tcpdf.org/examples/example_003/

Upvotes: 0

olger
olger

Reputation: 492

Use the getNumPages function instead:

$total = $pdf->getNumPages();

Note that this counts the amount of pages that have been created so far using the Addpage() function. So if you want the total amount of pages declare it after your last use of Addpage()

Upvotes: 2

Related Questions