How to Put Page Number in PDF using C#

This how-to guide describes how to put page number in PDF using C#. It shares all the resources required to write this application, a complete program flow, and a runnable sample code to put page numbers on PDF using C#. It provides you the option to automatically render page numbers on the entire PDF without using any third-party tool or software.

Steps to Insert Page Numbers in PDF Document using C#

  1. Set the IDE to use Aspose.PDF for .NET to put page numbers
  2. Load the source PDF into the Document class object for adding pagination
  3. Create a page number stamp and set its formatting and display features
  4. Parse through all the PDF pages and put the stamp on it
  5. Save the resultant PDF file after adding page numbers

These steps sum up the process to add pagination to PDF using C#. The process is commenced by loading the target PDF file followed by the creation and customization of the PageNumberStamp class object. In the final step, this stamp is put on each page of the PDF document where page numbers are automatically incremented and finally this PDF file is saved on the disk.

Code to Add Page Numbers to PDF File using C#

The above code demonstrates the process to insert page number in PDF using C#. The main class that is used for this task is PageNumberStamp as it contains properties to set the formatting of the pagination and other display parameters like the margins from the edges of the page, horizontal and vertical alignment on the page, and the index from which the page numbers are to be started to list a few. In the final steps before saving the PDF, the stamp is placed on each page however you may skip some pages if required.

This article has guided us to put page number in PDF using C#. If you want to learn the procedure to add digital signatures to a PDF file, refer to the article on how to add digital signature to PDF in C#.

 English