It is actually a simple solution to get a total number of pages in pdf file. I found it from devasp and I think it's worth to share.
using System.IO;
using System.Text.RegularExpressions;
public static int GetNoOfPagesPDF(string FileName)
{
int result = 0;
FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
StreamReader r = new StreamReader(fs);
string pdfText = r.ReadToEnd();
System.Text.RegularExpressions.Regex regx = new Regex(@"/Type\s*/Page[^s]");
System.Text.RegularExpressions.MatchCollection matches = regx.Matches(pdfText);
result = matches.Count;
return result;
}
Wednesday, March 24, 2010
Subscribe to:
Post Comments (Atom)
1 comment:
thnx for sharing such a valuable information….I am using zetpdf to generate pdf in asp.net…I would also suggest you to use zetpdf…It makes the job easy..
Post a Comment