In this tutorial, I'll show you how to get number of page in pdf file using C#.NET

You can design a simple UI allows you to select a pdf file, then count number of page in a pdf file and display it in a textbox control


To play the demo, you need to install itextsharp from Manage Nuget Packages

As you know, itextsharp is an open source that helps you to create the pdf document, or you can also use itextsharp to embed a signature to the pdf file

string path = @"C:/yourfile.pdf";
PdfReader pdfReader = new PdfReader(path);
int numberOfPages = pdfReader.NumberOfPages;


You can use the NumberOfPages property to count the number of page in a pdf file