Page Numbering on Existing PDF

Page Numbering on Existing PDF

Forum member · Jul 16, 2011
Hello, I am evaluating your software and what my business need is a way for me to put page numbering on existing pdf document. I have figured out a way to do that using PageNumbering Label object along with PageTemplate object. It works well, however some of our documents may comtain both landscape and potrait pages, so I am looking for a way to position the page numbering label based on the properties of each individual page. Is there a way to do that using your library? Thank You. Daniel

Re: Page Numbering on Existing PDF

Support · Jul 18, 2011
Hello Daniel, Yes, you can add page numbers to the already existing PDF documents using PageNumberingLabel without any problem. If the document is having pages with different page dimensions(width and height) then you will need to loop through each page in the document and place the PageNumberingLabel dynamically by calculating the X and Y positions for it. Below is the sample code for it. MergeDocument document = new MergeDocument(@"C:\MyDocument.pdf"); PageNumberingLabel pageNumber; for (int i = 0; i < document.Pages.Count; i++) { Page page = document.Pages[i]; float yPosition = page.Dimensions.Height - (page.Dimensions.BottomMargin + page.Dimensions.TopMargin); float pageNumberWidth = page.Dimensions.Body.Width; pageNumber = new PageNumberingLabel("%%CP%%of%%TP%%", 0, yPosition, pageNumberWidth, 20); pageNumber.Align = TextAlign.Center; page.Elements.Add(pageNumber); } document.Draw(@"C:\Test.pdf"); Thanks, ceTe Software Support Team.