Page Number

Page Number

Forum member · Nov 5, 2009
Hi, I am trying to display total page number on the cover page of my pdf document. There are n number of pages after the cover page. I created a gloabel variable and used on the first page like below but I get 0 for count. After I wrote all the pages I am resetting the intPageCount = document.Pages.Count. What I am doing wrong? Please advise me. PageElements.FormattedTextArea formattedpageNumberText = new PageElements.FormattedTextArea("  Page " + 1 + " of " + intPageCount, 0, 0, 180, 0, styleHdrData); float pageNumberHeight = formattedpageNumberText.GetRequiredHeight(); formattedpageNumberText.Height = pageNumberHeight; row.Cells.Add(formattedpageNumberText); After some code............. intPageCount = Report.Pages.Count; Thanks.

Re: Page Number

Support · Nov 6, 2009
Hello, You are getting the PageCount displayed as zero on the cover page most likely because you are adding the PageCount to the PDF document at the initial stage where in no pages are added to the document. The page elements will be added to the PDF document sequentially as you add them in your code. You will have to build the whole document and then later you can build the cover page and then you can get the PageCount and add it to the cover page using the Table. Plesae find the below code for it. Document doc=new Document(); Page coverPage = new Page(); doc.Pages.Add(converPage); for (int i = 0; i < 5; i++) { Page page = new Page(); Label label = new Label("Page Number "+(i+1), 100, 100, 200, 20); page.Elements.Add(label); doc.Pages.Add(page); } Table table = new Table(100,100,200,400); table.Columns.Add(100); FormattedTextAreaStyle style = new FormattedTextAreaStyle(FontFamily.Helvetica, 12, false); for (int j = 1; j <= doc.Pages.Count; j++) { Row row = table.Rows.Add(20); FormattedTextArea formattedpageNumberText = new FormattedTextArea(" Page " + j + " of " + doc.Pages.Count, 0, 0, 100, 20, style); float pageNumberHeight = formattedpageNumberText.GetRequiredHeight(); formattedpageNumberText.Height = pageNumberHeight; row.Cells.Add(formattedpageNumberText); } coverPage.Elements.Add(table); doc.Draw(@"Path to save the PDF document"); Thanks, ceTe Software Support Team