This post shows you how to get the number of page in a pdf file using C# .NET.

We will use itextsharp to read a pdf file, itextsharp is an open source library that helps you create a pdf or manipulate data with pdf files.

If you haven't got itextsharp in your project, you can download and install it from manage nuget packages in your visual studio.

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

You can use the NumberOfPages property to get how many number of pages in a pdf file.