I use FPDF to create invoices, and I had to get around the problem when printing multiple documents. I create several (2 to 100+) invoices for printing, so I built a foreach loop around my FPDF code to put all my invoices in one PDF file so that I can click print and do it. The problem is that FPDF uses PageNo () and {nb} to create page numbers and the total number of pages in the header, and if I have 500 pages that it lists as Page: 1 of 500, Page: 2 of 500, Page: 3 of 500 ... etc.
I need to figure out a way to create a page counter and the current page in the account. Therefore, if the first invoice is 3 pages, he says: Page 3 of 3, Page: 2 of 3, etc., And the next invoice is 5 pages, Page: 1 of 5, Page: 2 of 5 etc .... even though all this is in one PDF file.
$pdf=new PDF(); foreach ($array_invoices as $invoice_number) { ...FPDF Template Here... if($pdf->GetY() < 225) $pdf->SetY(238); elseif($pdf->getY() > 240) $pdf->AddPage(); } $pdf->Output();
The template has a header that displays the page number ...
$this->Cell(94,0,'page '.$this->PageNo().'/{nb}' ,0,0,'R');
source share