Count pages in a PDF file
This code shows how to count pages in a pdf file..
//Function for finding the number of pages in a given PDF file
string PgCount = string.Empty;
System.IO.FileInfo fextension = new FileInfo(vfileName);
string extension = fextension.Extension;
bool flag = UploadFile(vfileName);
if (extension == ".pdf" || extension == ".PDF")
{
FileStream fs = new FileStream(vfileName, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
string pdf = sr.ReadToEnd();
Regex rx = new Regex(@"/Type\s/Page[^s]");
MatchCollection match = rx.Matches(pdf);
if (flag == true)
{
PgCount = match.Count.ToString();
}
}
Dharmaraj's code logic was what I needed for my program. I'm using VB .Net instead C#. Below is the function I created in VB based on the above code.