2

I use AxAcroPdf to display PDF file with this code :

AcroPdfViewer.src = FilePath;
AcroPdfViewer.setPageMode("none");
AcroPdfViewer.setZoom(100);
AcroPdfViewer.setShowToolbar(true);

How can I get number of total pages of the PDF file in AxAcroPdf ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ali Ahmadi
  • 2,387
  • 4
  • 31
  • 48

3 Answers3

1

I think the best way to perform a pdf page count is the following:

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;

    }

Hope it helps ;)

Source: Counting PDF Pages

0

2018 edit: as commented below, the original answer referenced a method that is not an AxAcroPdf method. But an accepted answer cannot be deleted, so I have to leave it here.

stuartd
  • 70,509
  • 14
  • 132
  • 163
  • 2
    My alowed functions are : GetVersions,GetType,GetPreferredSize,GetOcx,GetNextControl,GetLifetimeService,GetHashCode,GetContainerControl,GetChildAtPoint. I can't access to GetNumPages ! , How can I use it ? – Ali Ahmadi Jun 08 '12 at 12:50
  • Youy're seeing the methods on the ActiveX Host control - use GetOcx() to get a reference to the AxAcroPdf control. – stuartd Jun 08 '12 at 13:20
  • 2
    It doesn't seem to be a part of the AxAcroPdf class whatsoever. According to the doc it is a part of the PDDoc class. I am having the same issue as ahmadi is where it is not shown as an available method... – Paul Aug 23 '13 at 21:32
0

You cannot get number of pages via AxAcroPDFLib.AxAcroPDF if you have only Acrobat Reader installed.

As for the first answer, using GetNumPages() requires you to install Acrobat SDK. Plus, you need to have standard or professional Adobe Acrobat Reader (NOT FREE) to use this API.

In terms of the second answer, it doesn't work in many cases. Not all pdf documents have "/Type /Page" tag.

But you can try other APIs to get the number of PDF pages. You can see this question.

Community
  • 1
  • 1
eriee
  • 416
  • 2
  • 15