This Way:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string ppath = Server.MapPath("~/Docs/Doc1.pdf");
PdfReader pdfReader = new PdfReader(ppath);
int numberOfPages = pdfReader.NumberOfPages;
Response.Write(numberOfPages);
}
}
Download the Latest iTextSharp.dll
Without using iTextSharp.dll
protected void Page_Load(object sender, EventArgs e)
{
FileStream fs = new FileStream(Server.MapPath("Docs/Doc1.pdf"), FileMode.Open, FileAccess.Read);
StreamReader r = new StreamReader(fs);
string pdfText = r.ReadToEnd();
Regex rx1 = new Regex(@"/Type\s*/Page[^s]");
MatchCollection matches = rx1.Matches(pdfText);
Response.Write("The PDF file has " + matches.Count.ToString() + " page(s).");
}
namespace:
using System.IO;
using System.Text.RegularExpressions;
Thank You.