Working with Stamps and Watermarks - facades

Add Page Number in a PDF File (facades)

PdfFileStamp class allows you to add page numbers in a PDF file. In order to add page numbers, you first need to create object of PdfFileStamp class. If you want to show page number like “Page X of N” while X being the current page number and N the total number of pages in the PDF file then you first need to get the page count using getNumberOfpages property of PdfFileInfo class. In order to get the current page number you can use # sign in your text anywhere you like. You can format the page number text using FormattedText class. If you want to start the page numbering from a specific number then you can set setStartingNumber property. Once you’re ready to add page number in the file, you need to call addPageNumber method of PdfFileStamp class. Finally, save the output PDF file using Save method of PdfFileStamp class.

The following code snippet shows you how to add page number in a PDF file.