Jump to content

retrieve current page number in word and reader


Recommended Posts

hello all. i am not so new to programming in general but new to AutoIt. I am very impressed and glad I found it. I have already created a very useful program for a friend of mine to facilitate copying and pasting info, as well as running all sorts of functions on the copied data and then grabbing the array and filling it into a proprietary software app his business uses.

The one great wall I have come up against is figuring out the current page (in either Adobe Reader or Word) that the user is on when a selection is made. I have scoured the forum and found lots of info to get this far and don't see anything referring specifically to a function that could handle this.

So, is there any way to obtain this information (not total pages, but current page from the cursor selection) from Adobe Reader and Word? My guess is no on both.

In that case, is the only other option using OCR to grab the info from the screen (and make sure the window hasn't moved)?

Also, I have seen some references to something written by someone to interact with another pdf reader, which is an option if that is possible to obtain the info that way, but I would still need it to work from Word too.

Your input is greatly appreciated.

Thanks,

Aaron

Link to comment
Share on other sites

If you've used the Word.au3 UDF, you might try:

; wdActiveEndAdjustedPageNumber returns the number of the page that contains the active end of the specified selection or range. 
; If you set a starting page number or make other manual adjustments, returns the adjusted page number.
Global Const $wdActiveEndAdjustedPageNumber = 0x1 

; wdActiveEndPageNumber returns the number of the page that contains the active end of the specified selection or range, 
; counting from the beginning of the document. Any manual adjustments to page numbering are disregarded.
Global Const $wdActiveEndPageNumber = 0x3   

; ... get document reference to $oDoc and select item of interest

$iPage = $oDoc.Application.Selection.Information($wdActiveEndAdjustedPageNumber)

; or...

$iPage = $oDoc.Application.Selection.Information($wdActiveEndPageNumber)

:D

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

A quick solution via reading the page control.

Pay attention that Adobe changes from version to version

the edit controll classNN and also the ctrlname.

The attache script works with Reader v9.

HTH, Reinhard

Opt("WinTitleMatchMode", 2)
$ViewerCtl = "[CLASSNN:Edit5]"

ViewerGetPage()

Func ViewerGetPage()
    if WinExists("Adobe Reader") Then
        $ViewerHd = Winactivate("Adobe Reader")
        $xTxt = ControlGetText ($ViewerHd, "",$ViewerCtl)
        msgbox(0,"Reader actual Page",$xTxt)
    endif
Endfunc
Edited by ReFran
Link to comment
Share on other sites

Great! Thanks to both of you for the tips. Funny, I did quite a bit of searching on this in the forums but perhaps didn't search for it the right way as I was convinced from what I read it wouldn't be possible. I will have to look into the versions in use by all the employees that will use this.

I have been sidetracked for a couple of days and will try to plug these ideas in soon and post the results.

--

Aaron

Edited by trailwalker
Link to comment
Share on other sites

Hello all and thanks again for all the help! Here is basically what I have:

If $ext = ".doc" Then
    ; its Word doc, get page using Word UDF
    $oWordApp = _WordAttach($file, "FileName")
    $pg = $oWordApp.Application.Selection.Information($wdActiveEndPageNumber)
    If Not @error Then
        $oDoc = _WordDocGetCollection($oWordApp, 0)
        $page = $pg
    Else
        ; error getting page automatically
        $do_page = 1
    EndIf
ElseIf $ext = ".pdf" Then
    ; its a pdf, get page with page control
    $ViewerCtl = "[CLASSNN:Edit5]"
    $ViewerHd = WinWait($file)
    $pg = ControlGetText($ViewerHd, "", $ViewerCtl)
    If $pg >= 1 Then
        $page = $pg
    Else
        ; error getting page automatically
        $do_page = 1
    EndIf
EndIf

This works beautifully with one exception. As was mentioned previously, the portion pertaining to the pdf breaks (well, gives the proper error) when its another version.

So, is there any way to find out how to set that ControlGetText for various different versions of Adobe? I am not sure where to find this info. Then I can plug in a little function which will check their version first when the file is selected and set the info appropriately to get the page number. Or, if anyone has a better solution, suggestions are welcome.

Thanks!

--

Aaron

Link to comment
Share on other sites

Nevermind on the question of how to find out the name of the controls, I just found the Window Info Tool. Great tool!

So, only question remaining is, based upon the mess I will no doubt have for the various version changes in Reader, not to mention the need for constant updating as they continue to do so, is there a better way to do what I am trying to do?

Thanks!

Aaron

Link to comment
Share on other sites

  • 3 weeks later...

.... is there a better way to do what I am trying to do?

Oh, didn't read this. Thought I would get automatic an email.

Yes there is a better solution in the case you know the full name.

Let me know if you need furtheron a solution.

br, Reinhard

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...