开发者

Counting the pages in a PDF file [closed]

开发者 https://www.devze.com 2023-01-19 04:48 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, vi开发者_运维问答sit the help center. Closed 9 years ago.

I know of several tools/libraries that can do this but I want to know if this is possible with just opening up the file as a text file and looking for a keyword.


have a look at this: http://www.freevbcode.com/ShowCode.asp?ID=8153
Edit: not work, may be too old
Found this:

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;
        }

Ps: tested! It works.see here source


[Edit: based on the edited question]

It is possible by reading it as text file and some minimal parsing.

If you read the pdf yourself then you will need to do the parsing. Each page in a PDF is represented by a page object.

The following provides an understanding about the pdf specification in short for pages and the link to the pdf spec.

  • http://help.4xpdf.com/questions/8/how-to-programmatically-count-the-number-of-pages-in-a-pdf


The xpdf utilities package (called xpdf-utils in debian) includes an application called pdfinfo. It will print out the number of pages in the file, among other data.

http://www.linuxquestions.org/questions/programming-9/how-to-find-pdf-page-count-699113/

0

精彩评论

暂无评论...
验证码 换一张
取 消