Count pages in a PDF file

I know several tools / libraries that can do this, but I want to know if this is possible only by opening the file as a text file and looking for a keyword.

+3
source share
3 answers

take a look at this: http://www.freevbcode.com/ShowCode.asp?ID=8153
Edit : doesn't work, maybe too old
Found:

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: checked! He works. see here source

+3
source

[Edit: based on edited question]

This is possible by reading it as a text file and a little minimal parsing.

pdf , . PDF ​​ .

pdf pdf.

+1

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

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

-1
source

Source: https://habr.com/ru/post/1768008/


All Articles