How to obtain the total page count for a pdf in iTextSharp?

Emanuel picture Emanuel · Sep 23, 2011 · Viewed 9.4k times · Source

I've created a class that extends PdfPageEventHelper to add a specific message at the end of the page. The problem is that this text need to be added only to the end of the PDF (if I have 3 pages this text need to be displayed only on the footer of the last page).

In the OnEndPage function of the PdfPageEventHelper class I use document.PageNumber to know what page I'm modifying, but how can I know if this page is the last one?

Thanks.

Answer

VahidN picture VahidN · Sep 23, 2011

(writer.PageNumber - 1) is the last page.