FPDF Multiple Documents Generated In One PDF, Need To Reset Page No Per Document - fpdf

I am using FPDF to generate invoices and I had to work around an issue when printing multiple documents. I am generating multiple (anywhere from 2 to 100+) invoices for print so I built a foreach loop around my FPDF code to put all my invoices in one PDF so I can hit print and be done. The problem is, FPDF uses PageNo() and {nb} to generate page numbers and the total page count in the header and if I have 500 pages it lists as Page: 1 of 500, Page: 2 of 500, Page: 3 of 500... etc.
I need to figure out a way to generate a page count and current page by invoice. So if the first invoice is 3 pages it says Page: 1 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 it's all in the same PDF.
$pdf=new PDF();
foreach ($array_invoices as $invoice_number) {
...FPDF Template Here...
/**
* The following code checks the page length
* If the page is over a certain length it will create a new page.
* If not, it will add the footer.
*/
if($pdf->GetY() < 225)
$pdf->SetY(238);
elseif($pdf->getY() > 240)
$pdf->AddPage();
}
$pdf->Output();
The template has an include to the header which outputs the page number...
$this->Cell(94,0,'page '.$this->PageNo().'/{nb}' ,0,0,'R');

It is possible to create pagegroups, where every group has its own pagerange there is already an addon that will do the work for you: fpdf addon page groups

Related

page number inside section

I have a section and I am trying to use the page number from word and I am getting page 1 in all pages.
I try link headers but I don't want the same header n my last page
header
<?for-each#section:G_1?>
page1/2
here is table i want to show up in every page
<?end for-each?>
-------------------------------------------
main body i have some groub by in tables
----------------------------------
i have different last page that calculate all my resuts and with no header
page1/2 <here is the error i want 1,2,3,4/120> and iam getting 1,1,1,1,1,1,1/2
Sections will reset page numbers.
You can bypass this by putting the following code anywhere in your template:
<?initial-page-number:'AUTO'?>

Multiple page numners in HTML2PDF

I have more than 20 letters which I am printing into PDF using html2pdf. The HTML code goes inside the foreach loop, I am using the ... data ... in the foreach loop to print each letter. However the page numbers that are comming is applying to the entire PDF, I would like the page number to reset for each tag in the PDF. Ex if letter1 goes up 2 pages, then for letter 2 in the same PDF it should start the page number from 1. Below goes my sample code. I am wondering if there is any alternative solution to fix it.
foreach ($orders as $order)
{
?>
<page backtop="10mm" backbottom="10mm" backleft="8mm" backright="8mm">
<page_header>
<div style="width:730px; text-align:right;"><?php echo $order->order_id;?> page [[page_cu]] of [[page_nb]]</div>
</page_header>
..HTML code of my letter goes here
</page>
<?php
}
?>
Ex- If we have 3 letters the page number goes like
page 1 of 3
page 2 of 3
page 3 of 3
Instead I want page 1 of 1, page 1 of 1, page 1 of 1 for each 3 letters. Note that a letter may have more than one page so for such situation it should be like page 1 of 2 for letter 1 first page, page 2 of 2 for letter 1 second page, then for letter 2 it should again start from page 1 of 1.
I have tried to be more clear regarding my question, kindly let me know if I am confusing here.
Thanks in advance.
look at the html2pdf examples. There are sample that uses [page_cur][page_nb] (something similar to that). That special tags render page number and page count.

How to add page number in multipage pdf report

I have created multiple pages pdf report using iReport as below.
Pdf report
How to put page number like (page 1 of 2) in this pdf report ?
If i will put same in iReport it will take all pages as separate page and give numbers accordingly, like:
for page1.jrml >> page 1 of 2 and page 2 of 2
for page2.jrml >> agian same page 1 of 1
...
it should be like:
for page1.jrml >> page 1 of 3 and page 2 of 3
for page2.jrml >> page 3 of 3
Please suggest.
You page numbering won't be correct because by using that approach you are creating 2 reports and merging them into 1 PDF, instead of creating a single report.
If you embed the second report into the first as a subreport, the page numbering should then be correct.
Im guessing you are putting the page number inside subreport. Page numbers should be in the page footer section of the main report.

Alter the page numbers on a pdf created with PdfSharp/Itextsharp

I am using PdfSharp/Itextsharp to stitch together a number of documents and stamp a page number at the bottom of each page. The first document in the package is the Table of Contents and is not paginated. I start the pagination with the first page after ToC. The problem is the page number that is displayed on the document is not the same as the page number indicated by the Adobe Reader.
I checked with other documents and it looks like pdf supports the option to somehow reset the page number so page 1 can start again later in the document.
How can I do this with pdfsharp or itextsharp?
The page numbers shown in Adobe Reader are defined by "Page Labels".
For instance: you number the TOC with i, ii, iii, iv, v and so on. The real page numbers are 1, 2, 3, 4, 5, and so on.
Here's a Java example from my book that shows how to work with Page Labels: http://itextpdf.com/examples/iia.php?id=234 [archived] It should be very easy to adapt it for use in C#.
If not, look for the corresponding example on this site: http://kuujinbo.info/iTextInAction2Ed/index.aspx

I use itext.dll for generating a PDF using ASP.NET and I want a footer in my document?

I use itext.dll for genrating a PDF using ASP.NET and I want a footer in my document in the form of:
Page 1 of 6
HeaderFooter footer = new HeaderFooter(new Phrase("Page"), new Phrase(" of 6"));
footer.setBorder(Rectangle.NO_BORDER);
footer.setAlignment(Element.ALIGN_CENTER);
document.setFooter(footer);
Is this possible without hardcoding the total number of pages? I.e. is there a method to get the total number pages in a document?
I have found that there are (at least) 2 ways of doing this.
One is to create the document without the footer and after that use PdfStamper to stamp the page numbers with total on it. But that raised some problems with me when I output the stampers product to MemoryStream and there seems to be no way of closing the stamper without closing the stream at the same time.
The other way is to create one instance of PdfTemplate that will represent the total page count and add that to every page to footer or where ever you want it.
Next you can use your own PdfPageEventHelper class and implement OnCloseDocument method where you can fill the template with total page count:
public override void OnCloseDocument(PdfWriter writer, Document document)
{
PageCountTemplate.BeginText();
PageCountTemplate.SetFontAndSize(HeaderFont.BaseFont, HeaderFont.Size);
PageCountTemplate.ShowText((writer.CurrentPageNumber - 1).ToString());
PageCountTemplate.EndText();
}
I personally also use OnOpenDocument to create the template and OnEndPage to write it on each page.
EDIT:
To answer Jan's question, OnCloseDocument is called only once when the whole doc has been written. When Doc.Close() is called I mean.