Posted by: R Manimaran | October 17, 2007

Count No. of pages in a pdf file using Regular Expression

Number of Pages in a PDF 

FileStream fs=new FileStream(@”E:\Dotnet.pdf”,FileMode.Open,FileAccess.Read);

StreamReader rdr=new StreamReader(fs); string pdfText=rdr.ReadToEnd();Regex rx1=new Regex(@”/Type\s*/Page[^s]”);

MatchCollection matches=rx1.Matches(pdfText);MessageBox.Show(“The pdf File has “+matches.Count.ToString() +” Pages”);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: