PDF file's current page No. ? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Posts: 388
Joined: 20 Sep 2014, 06:15

PDF file's current page No. ?

18 Jun 2017, 20:54

I'd like to grab "the number of current page" of active pdf file.
I found this code.
But, it emits error only.

Code: [Select all] [Download] GeSHi © Codebox Plus

ob := ComObjCreate("AcroExch.App")    ; error comes here.
ad := ob.GetActiveDoc
pd := ad.GetPDDoc
js := pd.GetJSObject
MsgBox % js.Path ; first step only. My goal it to know the current Pg. No.
What do I have to do ?

Adobe Reader X
AHK 64 Unicode
Win 8.1

User avatar
Posts: 1970
Joined: 17 Oct 2015, 20:28

Re: PDF file's current page No. ?  Topic is solved

19 Jun 2017, 00:14

I have Adobe Reader XI (on Win 8.1; AHK 32 Unicode I believe), so this may need to be adjusted for you.

I retrieve the pagenumber by using ControlGetText. I use this line in one of my scripts:

Code: [Select all] [Download] GeSHi © Codebox Plus

ControlGetText, reader_page, Edit2, % "ahk_id " Reader%A_Index%

So the control Edit2 is what contains the value of the page number for me.


One thing I will note is that if you need the active PDF file and still want to try to use it as a COM Object (in case of other manipulation beyond just getting a page number), do you want ComObjCreate() or ComObjActive()? I've seen Active used when taking control of something already open.
Posts: 388
Joined: 20 Sep 2014, 06:15

Re: PDF file's current page No. ?

19 Jun 2017, 06:12

It works.
This is a nice workaround.

Posts: 608
Joined: 30 Sep 2013, 22:25

Re: PDF file's current page No. ?

19 Jun 2017, 14:48

If you want to do it through COM along the lines of original post, you can try this:

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

App := ComObjCreate("AcroExch.App")
AVDoc := App.GetActiveDoc()
AVPageView := AVDoc.GetAVPageView()

MsgBox % AVPageView.GetPageNum
It is important to realize that Acrobat uses a zero index for page numbers internally, meaning that the first page is zero. So for most cases you would add +1 to this number to get the page numbers that most would expect.

This is for the full Adobe Acrobat. I do not believe the free Reader has full COM support that would allow this method.

Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

Google Search, Dictionary, Thesaurus - Quickly Get Information from Specific Web Resources

[Function] Timer - Create and Manage Timers

Return to “Ask For Help”

Who is online

Users browsing this forum: divanebaba, Riki81, Xtra, Yahoo [Bot] and 61 guests