Please help me
Please help me

Reputation: 81

How to get the current page count?

Hi i have to create a pdf document from a grid view. Thus this is the problem that i encountered. When i tried to count the total number of pages, i cant seems to get the amount. Please help

THis are some of the coding i tried but to no avail.

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

i tried to append the total page to my integer however for the first one what ive got is that page count is a writeOnly value while pagesize if i am not wrong is the size of the document.

Please help me thank you

Upvotes: 0

Views: 2078

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

Your error is based on a misunderstanding of the basic concepts of iTextSharp.

A document is created in 5 steps:

  1. Create a document. This document doesn't know anything about the presentation of the document, only about its content.
  2. Create a writer. You are creating a PdfWriter that will translate the content into a presentation, more specifically into a PDF document with one or more pages.
  3. Open the document.
  4. Add content.
  5. Close the document.

You are asking the document object for the current page number, yet the document isn't aware of its presentation. It doesn't even know that a PDF is produced.

You should ask the writer that is responsible for creating the PDF how many pages were already created; writer.PageNumber will return that number.

Upvotes: 4

Related Questions