iText

How to get the current page count?

When I try to count the total number of pages, I don't get the current amount. Why is that?

I have to create a PDF document from a grid view. When I try to count the total number of pages, I don't get the current amount.

C#
Dim pdfDoc As New Document(PageSize.A2, 50, 50, 50, 50) ................... pdfDoc.PageCount

Posted on StackOverflow on Jul 21, 2014 by Please help me

First of all you should create a PDF document in a right way. In iText 7 you’ll need:

Java
PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));

Now you can refer to this object to know the number of pages in the document:

Java
pdfDoc.getNumberOfPages();

Click How to get the current page count? | iText 5 PDF Development Guide if you want to see how to answer this question in iText 5.