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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
IMEime
Posts: 750
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

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

Regards
User avatar
Exaskryz
Posts: 2882
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

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.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: PDF file's current page No. ?

19 Jun 2017, 06:12

Hooo.
It works.
This is a nice workaround.

thanks
User avatar
FanaticGuru
Posts: 1906
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

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.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Lisa19
Posts: 48
Joined: 07 Apr 2019, 22:25

Re: PDF file's current page No. ?

22 Mar 2020, 14:18

@FanaticGuru thanks a lot!

I'm trying to understand how this work, could you please show me how I could highlight a selected text?

I tried to add this line just after your code (it did not work)

Code: Select all

        page= % AVPageView.GetPageNum +1 ; first page is  0
        AVDoc.PDTextSelect.highlight
Thank you

For those looking for the API docs:
https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/iac_developer_guide.pdf

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ntepa and 253 guests