Jump to content

How do I GetZoomLevel()


Recommended Posts

I have checked everywhere in the forums (I think) but I can't find a function or a com method example to get the current zoom level in an open pdf file. If the level is visible (on the toolbar) of the pdf viewer (acrobat), it is retrievable as visible text but if its not visible, can someone please show me how to retrieve it. Thanks in anticipation.

Link to comment
Share on other sites

Full Acrobat ($$$-product) or free Reader only.

Which Version (9.x)?

Reinhard

PS: You may have a look at this: http://www.autoitscript.com/forum/index.php?showtopic=109859&view=findpost&p=773004

The ClassNM in the actual reader version is Edit4

Edited by ReFran
Link to comment
Share on other sites

Full Acrobat ($$$-product) or free Reader only.

Which Version (9.x)?

Reinhard

PS: You may have a look at this: #773004

The ClassNM in the actual reader version is Edit4

Thanks Reinhard

I use Pro Extended 9.3.1 but I must assume that other users of this script (if any) might use a free viewer or another pdf viewer. Is this an issue? I went through your code.

My first post already mentioned that I can already get the zoom-level from the visible text but I don’t want to do it that way because if the control is not visible (i.e. removed from the toolbar) then nothing shows.

I would not do it your way anyway because as you say ClassNN is Edit4 but this control can and will change each time it is created by Adobe.

A better way to avoid the changing control class names is using WinGetText() - you can then search for the % and extract the number from there. There are many ways to extract this visible zoomlevel % and I have tweaked your variables below for rough illustration purposes only.

However I’m not looking to use this approach because if the zoomlevel is not visible (ie removed from toolbar) both ControlGetText() and WinGetText() will show nothing.

I’m looking to get the value of the Object property PageSetUp.Zoom (or similar) - irrespective of visibility.

Thanks again, Russell

;Note you might need to substitute “Adobe Acrobat” with “Adobe Reader” or “Adobe” will work if no other Abode product is running. 

Opt("WinTitleMatchMode", 2)
;$ViewerCtl = "Edit3"
ViewerGetPage()

Func ViewerGetPage()
    if WinExists("Adobe Acrobat") Then
        $ViewerHd = Winactivate("Adobe Acrobat")
     endif    
        $xTxt = WinGetText("Adobe Acrobat")
         $xTxt = StringMid($xTxt,(StringInStr($xTxt,"%")-7),8); assumes zoomlevel will be < 9999.99%
         $xTxt = StringMid($xTxt, StringInStr($xTxt,Chr(10),-1),8)
         msgbox(0,"ReturnTxt2",$xTxt)
         
Endfunc
Link to comment
Share on other sites

For Acrobat you can use the JS-Object Doc.zoom to get or set the zoom level.

With Reader you can set the zoom with app.execMenuItem("ZoomTo") - manual = ctrl+Y.

If you have set it, you can also get it with this command

But I didn't found a solution to get it more simple.

With app.execMenuItem(..) you should beable to make sure that the toolbar "zoomlevel" is visible.

HTH, Reinhard

Link to comment
Share on other sites

For Acrobat you can use the JS-Object Doc.zoom to get or set the zoom level.

With Reader you can set the zoom with app.execMenuItem("ZoomTo") - manual = ctrl+Y.

If you have set it, you can also get it with this command

But I didn't found a solution to get it more simple.

With app.execMenuItem(..) you should beable to make sure that the toolbar "zoomlevel" is visible.

HTH, Reinhard

Thank you so much for this info - the ^Y I understand and will now force a value if no zoomlevel is visible. I have no idea about app.execMenuItem(..) or how to implement it but would love to learn. If you can please point me in the direction of an Autoit example I would truly appreciate it (I searched and found nothing).

I have also decided that before I hop into any future thread I must tell the reader that I am an accountant and not a programmer. I’m okay with regular scripting but when outside calls are made to objects and dlls I know nothing except to follow the syntax of others (after I try to understand it).

There was an error in my last script $xTxt = StringMid($xTxt, StringInStr($xTxt,Chr(10),-1),8) should have read $xTxt = StringMid($xTxt, StringInStr($xTxt,Chr(10),0,-1)-1,8)

Also if I am to monitor any change in the zoomlevel it’s better to get the message from the control as you did and not the WinText. So I combined both methods to get ID and came up with a strange result?

Here is a revised version.

Thanks again, Russell

Opt("WinTitleMatchMode", 2)

$sWinTitle = "Adobe Acrobat"

$sTxt = ""

GetVisibleZoomLevel()
GetZoomControlID()

Func GetVisibleZoomLevel()
    If WinExists($sWinTitle) Then
        WinActivate($sWinTitle)
        $sTxt = WinGetText($sWinTitle)
        $sTxt = StringMid($sTxt, (StringInStr($sTxt, "%") - 7), 8); assumes zoomlevel <9999.99
        $sTxt = StringMid($sTxt, StringInStr($sTxt, Chr(10), 0, -1) + 1, 8)
        MsgBox(0, "", "ZoomLevel is = " & $sTxt)
    EndIf
EndFunc   ;==>GetVisibleZoomLevel

Func GetZoomControlID()

    $i = 2  ;Because Edit"1" also has zoom value?
    Do
        $sID = "Edit" & $i
        $sResult = ControlGetText($sWinTitle, "", $sID)
        $i = $i + 1
    Until $sResult = $sTxt
    MsgBox(0, "ZoomLevelControlID = ", $sID & " = " & $sResult)
    $x = ControlGetText($sWinTitle, "", "Edit1")
    MsgBox(0, "", "Edit1 also = " & $x)
    Exit
EndFunc   ;==>GetZoomControlID

Edit: Forget about everything else written above because the answer to the question - as it applies to Adobe Acrobat - is that Edit1 seems to be the holder of the zoomlevel, visible or invisible.

Edited by 1905russell
Link to comment
Share on other sites

Mmmh,

I tested again scripting with Reader (app.execMenuItem("ZoomTo"))

That seems not to work with newer versions,

so controlSend for Reader seems to be the first choise.

Attached a script which tell you which program/version will start pdfs.

$openExe = _DefaultPdfOpenExe()
msgbox(0,"",$openExe)

Func _DefaultPdfOpenExe()
    Local $ContentType
    $ContentType = RegRead("HKEY_CLASSES_ROOT\.pdf","")
    $openExe = RegRead("HKEY_CLASSES_ROOT\" & $ContentType & "\Shell\Open\Command","")
    return $openExe
EndFunc

If you work with full Acrobat (Acrobat.exe)

you can script it all:

$ok = msgbox(0,"","Show/Change zoom level of an active Doc in Acrobat")
if $ok = 1 then
    $App = ObjCreate("AcroExch.App")
    $AVDoc = $App.GetActiveDoc()
    $PDDoc = $AVDoc.GetPDDoc
    $JSO = $PDDoc.GetJSObject
    $x = $JSO.zoom
    msgbox(0,"","Zoom: "&$x&"%")
    $JSO.zoom=120
endif

HTH, Reinhard

Link to comment
Share on other sites

Thank you, Thank you, Thank you

You have given me exactly what I wanted (for Acrobat).

AcroExch.App is going to take some practice but I'm excited at the prospects of learning it.

I now have collected a ton of Autoit material on various aspects for a personal prototype project that seems to have taken over my life.

As mentioned I am an accountant and in North America "taxtime" is upon us and so alas Autoit must be shelved for a few months at which time I'll be back to bug everyone. Thanks again for the tremendous help. Russell

Edited by 1905russell
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...