468,541 Members | 1,775 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,541 developers. It's quick & easy.

Can we write code to count pages in a file irrespective of its type?

I have to count the number of pages in the document that I am uploading. This document can be a word file, xls, txt or pdf. I have my code working for pdf but not for other types. Here is the code that works for pdf- it uses regex

Expand|Select|Wrap|Line Numbers
  1. System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
  2.                 System.IO.StreamReader r = new System.IO.StreamReader(fs);
  3.                 string text = r.ReadToEnd();
  5.                 System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex(@"/Type\s*/Page[^s]");
  6.                 System.Text.RegularExpressions.MatchCollection matches = regx.Matches(text);
  7.                 noOfPages = matches.Count;

please help me with this. I am totally stuck.
Aug 27 '13 #1
0 900

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Marc | last post: by
2 posts views Thread by draganc | last post: by
5 posts views Thread by Daniel Corbett | last post: by
88 posts views Thread by Peter Olcott | last post: by
3 posts views Thread by belred | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.