$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); $pdf->AddPage(); $pdf->Cell(0, 10, 'Hello World!', 0, 1); if ($pdf->getPage() == $pdf->getNumPages()) { echo 'This is the last page.'; } else { echo 'This is not the last page.'; } $pdf->lastPage(); $pdf->Output('example.pdf', 'D');
require_once('tcpdf/tcpdf.php'); $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); $pdf->AddPage(); $pdf->Cell(0, 10, 'Page 1', 0, 1); $pdf->AddPage(); $pdf->Cell(0, 10, 'Page 2', 0, 1); if ($pdf->getPage() == $pdf->getNumPages()) { echo 'This is the last page.'; } else { echo 'This is not the last page.'; } $pdf->lastPage(); $pdf->Output('example.pdf', 'D');In this example, we create a new TCPDF object and add two pages with some text. We then check if the current page is the last page and output a message accordingly. Finally, we call the lastPage() function which sets the current page as the last page. The TCPDF library is a PHP package for creating PDF documents.