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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • discusshere
    New Member
    • Aug 2013
    • 2

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

    Hello,
    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

    Code:
    System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    System.IO.StreamReader r = new System.IO.StreamReader(fs);
                    string text = r.ReadToEnd();
    
                    System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex(@"/Type\s*/Page[^s]");
                    System.Text.RegularExpressions.MatchCollection matches = regx.Matches(text);
                    noOfPages = matches.Count;


    please help me with this. I am totally stuck.
    Last edited by Rabbit; Aug 27 '13, 08:24 PM. Reason: Please use code tags when posting code.
Working...