These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Obtaining current zoom and pan settings from AcroPDF1 (AcroPDF.DLL)

glassman
Registered: Apr 13 2009
Posts: 7

I am using the AcroPDF ActiveX object in a VB6 program. I have code that controls the zoom factor, and I also need to add code to control the panning, both which I can do, but the problem I'm having is I don't see any way (yet) to get feedback from the ActiveX object.

For example, I don't yet see any method or property like GetCurrentZoom or GetCurrentTop or GetCurrentLeft (you get the idea). Is there any way to get the ActiveX object to report to me what it's current zoom setting is, and what it's current top and left properties are set to so I know the exact positioning of the document in its viewer window?

My Product Information:
Acrobat Standard 9.1, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
It sounds like you are using the "AxAcroPDFLib.AxAcroPDF" interface? I haven't used the Acrobat ActiveX object embedded in a VB app, but I believe you should have access to the AcroExch object. If this is true, then you have access to a much wider set of functionality. The AcroExch.AVPageView object has a function for acquiring the current bounding box of the page view, "GetAperature".

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

glassman
Registered: Apr 13 2009
Posts: 7
Thanks for replying.

Yes, I'm using the AxAcroPDFLib.AxAcroPDF interface (by adding the component named "Adobe Acrobat 7.0 Browser Control Type Library" to my VB project. The VB Components window says this is mapped to "AcroPDF.DLL").

I don't find anything on my computer (in the VB list of objects) that implies I have access to an object called AcroExch. I only have the free Adobe Reader installed, and this is the same configuration that my clients will have..........the free Reader only.

Is it possible that the AcroExch object gets installed with something other than the free Adobe reader? If that's the case, is this an object I can redistribute? How do I obtain it?

Also, there are other issues that I'm addressing by the fact that AcroPDF lets me display the PDF from inside a VB form, and if AcroExch doesn't let me do that, I'll have further issues.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Do you have the IAC reference documents? These are really important. The AcroExch object is an ActiveX interface for Acrobat/Reader. It's called the InterApplication Communication Interface. You'll find the document here:
http://www.adobe.com/devnet/acrobat

Like I said earlier, I don't know if this interface is included with AxAcroPDFLib.AxAcroPDF object. I haven't played around with it much. If it is your're in luck. So it's worth reading over the documentation and trying to set it up. If it's not availible, then there is something else you can do but it means adding code to any PDF that's displayed in your application.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

glassman
Registered: Apr 13 2009
Posts: 7
I have POURED over that documentation, and 90% of it references things that I don't seem to have on my computer. I downloaded the Adobe SDK, yet the examples won't run in VB6. I have poured over that documentation FOR DAYS with no luck because it talks about objects that I don't have. So where does one go next? Trust me, I'm not the type who just posts stuff on these boards without having tried to read the docs.

If I knew how to instantiate ANY of the extra objects referenced in the Interapplication Communication (IAC) documentation, I would have never needed to post here! :)
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I figured you probably knew what you were doing. The problem with this, knowing what you're doing, is of coures that you've already exhusted the options by the time you go to the forums:( But just as a sanity check, try the following.

Make a new VB app and follow the directions in the IAC User Guide for setting up the AcroExch interface using the Acrobat Type Library, not the dll. You should be able to use this to open and extract information from and manipulate the view of PDF documents in Reader. This will validate that the interfaces exists and that you can use it. The next question is, can you use it with Acrobat.dll? And I don't know the anser to that one.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ntclark
Registered: May 21 2009
Posts: 4
glassman -

I may be a bit late here in providing your solution, but I want to do so because I solved this and other inane problems not long before your original post, and I very much feel your pain regarding both the lack of functionality with what you have in the pure Reader environment, and in the documentation regarding what or where this functionality is found.

I note 2 things:

1) The functionality for pure reader only intercommunication is not only limited, it is indeed, as you have found out - one-directional. It is the interface: IAcroAXDocShim

2) The document referred to here by thomp - is large and complex, that in and of itself is not a problem. Yet, AFAIK, no where in this document does it simply and explicitly state this fundamental fact, for Reader only - you have this interface and nothing else. I, like you, went through and through this stuff only to discover that 90% of it doesn't apply. Where this seems odd to me is that not requiring clients to have Acrobat ($$) would be of high value to you (the developer) in the reduced cost of distribution and licensing.

On to your initial problem.

True, you can set the zoom level but not determine it. You can set the page number but not retrieve it.

The solution involves programmatically reading the contents of the window that displays the zoom. To initiate this, find and read the windows API documentation on the EnumChildWindows API call.

Note that the toolbar above the pdf document in your window will have, as one of it's children (an edit control, I think) a window that contains the character '%'. Note that this is even true if you set the display of that tool bar to "off". Your job is to enumerate the child windows of the window in which you display the document (host the activex control from Adobe), looking for that window that contains '%'. Finding it, you obtain the full text of that window, and convert it to a number. That is your current zoom factor.

This is not trivial (the EnumChildWindows API will require you to create a "callback" function that it will use to notify you of what it finds, I expect that is doable in VB, but I cannot tell you how).

However, as a technical challenge, it can be a fun exercise and could very well lead to other capabilities that you do not yet know you need. For example, getting the current page #.


I see you also want to determine the position of the document within the window.

I also have a solution for this. If you are comfortable with sub-classing the reader's window that display's the pdf within VB (read the windows API documentation for SetWindowLong() ), I have C/C++ code that does this. You may not have to sub-class the window, but you will have to find and query the state of the two scroll bars in order to calculate what part of the document is currently "obscurred" - i.e., off the screen above/below, or right/left.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Wow!! That's really getting deep into the system. You can in fact call all of the Window's API functions from VB. It's been a while so I forget the exact technique, but I do remember it was a little non-standard for VB. And I'm not all that clear how subclassing would work from VB. But it's worth a try if you've got the programming chops. Since you are using VB6 this will probably be a bit easier and more feasible than using the newer .NET stuff.

But there is another techique that may be easier, if you can figure it out. There is a communication mechanism that availible between Acrobat JavaScript and Browser JavaScript through the Acrobat ActiveX Object. See this example:

http://www.windjack.com/WindJack/Browser2PDF/brwsr2acroJS.htm

The same mechanism should also be availible to the ActiveX object displayed in a VB app.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Kais Majbri
Registered: Feb 24 2010
Posts: 6
Hi ntclark,

i was trying to retrieve the page number of a pdf file. Im using reader not pro. I used the enumchildwindows to enumerate all the child windows of the window in wich i opened my pdf file. I got all the children windows but i can't go further to see what's inside them.

Can you help me a bit ?

Thanks in advance.
ntclark
Registered: May 21 2009
Posts: 4
Kais Majbri wrote:
Hi ntclark,i was trying to retrieve the page number of a pdf file. Im using reader not pro. I used the enumchildwindows to enumerate all the child windows of the window in wich i opened my pdf file. I got all the children windows but i can't go further to see what's inside them.

Can you help me a bit ?

Thanks in advance.
Note: This might be a duplicate post - replied just now but internet connection went down (?)

Kais,

What you need is the contents of the candidate child window that should contain your page number.

Once you believe you have the appropriate child window handle, call the GetWindowText API function to see if that window contains a number.

char szTemp[64]
GetWindowText(hwndChild,szTemp,64);

If szTemp comes back containing a number, it is likely you have the appropriate handle. If it contains a "%", then you probably have the zoom factor window handle, and keep searching for the page number handle.

If szTemp contains "i", "ii" - i.e., roman numerals - that probably also means you do have the correct handle.

The upshot is, call GetWindowText to get the contents of any window handle.

If you don't get a page # - you might have to refine your search using EnumChildWindows to look at more information about the candidate child windows.

Nate
oksana77
Registered: Apr 24 2009
Posts: 89
Thom wrote:
But there is another techique that may be easier, if you can figure it out. There is a communication mechanism that availible between Acrobat JavaScript and Browser JavaScript through the Acrobat ActiveX Object. See this example:[url]http://www.windjack.com/WindJack/Browse … acroJS.htm[/url]
I wonder what would be a communication mechanism for LifeCycle forms?
Kais Majbri
Registered: Feb 24 2010
Posts: 6
Hi ntclark,

I used Winspy++ to get to know wich class and aplication name to browse. I know now where to browse. But the error is the same... EnumChildWindows doesn't show hidden controls so i can see them in Winspy but can't get them from that method. Don't you know how to make that control visible or get the data in it even if it's hidden?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
okasan77,

At the top level, the document object level, there is no difference between a LiveCycle form and a regular PDF document. You can setup the Host Container message handler functions inside the Initialize or DocReady events.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ntclark
Registered: May 21 2009
Posts: 4
Kais Majbri wrote:
Hi ntclark,I used Winspy++ to get to know wich class and aplication name to browse. I know now where to browse. But the error is the same... EnumChildWindows doesn't show hidden controls so i can see them in Winspy but can't get them from that method. Don't you know how to make that control visible or get the data in it even if it's hidden?
Kais,

My sense is that you might need to double or triple check what is happening with EnumChildWindows.

I have never had any problem enumerating child windows - whether or not they are hidden. For example, the windows in the Reader Toolbar are discoverable via EnumChildWindows even if the entire toolbar itself is hidden.

As you know, EnumChildWindows takes a callback function that you provide. Make sure you don't return FALSE from this function until you find your window.

Aha - I've just thought of what might be the problem.

I actually call EnumChildWindows *from within* my callback function just to be absolutely sure I encounter ALL descendents of the given parent window.


I don't specifically know if this is necessary - but do it any way because it can't hurt.

Here's what I'm talking about:


1) In your callback function, Windows gives you a handle to a window - you inspect all of the attributes of that window to see if it is the one you want.

2) If it IS the window you want, you save the handle and return FALSE

3) If it IS NOT the window you want - you call EnumChildWindows again FROM your callback function - to enumerate the children of THAT window - you will end up recursively calling your callback function, this should not be a problem if you're prepared for it.

4) If this internal call of EnumChildWindows finds your window - return FALSE

5) otherwise return TRUE to indicate you want Windows to pass you the next child window.


So, you may be missing the window you are looking for because it is a Grandchild of the parent you start with.

Give that a try if you're not doing it already - I'm 90% sure that EnumChildWindows DOES provide a handle to all children (until you return FALSE), whether or not they are hidden.


Another thing that I learned with the Reader is that it must be completely loaded and initialized before starting all of this - if it hasn't gone through that process (which it has NOT until sometime AFTER loading the document), it will not have created all of it's windows yet.



Nate
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Hold on, Let's go back to the beginning. You said you are trying to get the page number. Why do you think that searching for child windows in Acrobat is going to help you? There are much simpler ways to go about this. For example using the ActiveX interface to Acrobat. Exactly what kind of application are you writing? And what is it's relationship to Acrobat on the system at runtime?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Kais Majbri
Registered: Feb 24 2010
Posts: 6
ntclark,

thank you so much for your help but i resolved the problem minutes after my post. I did'nt have time to reply. As i said some controls are hidden and can't be displayed by enumchildwindows ( you can see that the control hidden property in winspy++ wether it's shown or not in the acrobat toolbar). My original code used well the callback function and it displays in it all children available but it wasn't showing controls like page number or zoom, it was only showing the format of the current document page. I had to use the finwindowex function to go through the hierharchy and get the handle of the edit control and then get what's inside by the sendmessage function instead.

thomp,
using activex isn't the greatest choice especially for granting lots of access to client's computers. it's bad when you care about security , and activex isn't working on alot of browsers too ( im using web here ) . I tried the activex control on a windows application to see what i could do with the acrobat.dll and i don't have too many stuff that i can do without the acrobat pro and you cannot oblige a customer to buy the pro version to view some pdf. The whole job was to make annotations possible in an iframe web acrobat viewing. Foxit reader is a good choice for that but you cannot tell to customers to install it when there are hundreds of computers. So i used itext to do the annotation job my self but i had to be precise where to put that annotation so i had to come up with the page number and the cursor position in the iframe in the exact moment of adding an annotation ( this would be an external implementation).

If there is any way to do this i would be more than greatful :)
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You could do this with Reader displayed in the browser on a Comment Enabled PDF, with a little JS and prep work on the PDF itself. Acrobat/Reader in the browser will display the commenting toolbar and allow the user to place annotations. There is communication between JavaScript in the PDF and JS in the HTML. So you can activate tools in Acrobat from controls on the web page.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Kais Majbri
Registered: Feb 24 2010
Posts: 6
Thomp,

Comment enabled pdfs are made by pro and extended versions of acrobat. I even tried this by having a comment enabled file from a pro version and then tried to manipulate it but when i do any modification by itext on it , the file becomes disabled.

Tell me more about what you are thinking about.Thanks :)
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Well yes, you cannot modify a comment enabled PDF with iText, that's a no-no. The comments can only be added through Acrobat/Reader. If you want the user to add comments to a PDF while it is displayed in the browser, then two things need to be done to the PDF

1. It needs to be Comment enabled
2. THis line of code needs to be added to a document level script

Collab.showAnnotToolsWhenNoCollab = true

Now when the PDF is displayed the commenting toolbar will be visible and the user can add comments. You can also use the Acrobat ActiveX (the AxAcroPDFLib object) controls to change pages, load a new doc, etc. And all this happens client side with no special software installed on the users system. No server side PDF manipulation is necessary.


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Kais Majbri
Registered: Feb 24 2010
Posts: 6
So this is assuming I have to do these steps:

1- install acrobat extended/pro on my server
2- open every pdf file i have to manipulate automaticly with acrobat pro
3- enable this file
4- make an fdf file pointing to that newly enabled pdf


Even if I use this solution, I have to pay for acrobat pro but i have to find a solution for silent commands so that i can manipulate the pdf file without opening acrobat pro ( I knew acrobat isn't assuming this funnctionality anymore).

I think that getting the page number and the mouse position will be easier lol
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Actually, you can't use Acrobat on your server. That's also a no-no, in the licensing. Enabling and other document preparation has to be done manually on the client side before the PDF is uploaded to the server for distribution. Adobe does sell a Rights Enabling server, but if you think paying for Acrobat is bad you won't like the server.

So your going to install some special software on the client side for grabbing the page number by finding the page navigation window on the toolbar? What happens when this isn't displayed? You'd be much better off using the standard interfaces to acquire this info from Acrobat.

Have fun

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Kais Majbri
Registered: Feb 24 2010
Posts: 6
As a developer i would like to find the best way to implement something that doesnt need extra money for customers... I was asking for optimal solutions for me to do this... If the only solution for doing a secure implementation is to acquire a license then i would do like this. thanks for your support and explanations.

have a nice day
rerawa
Registered: May 5 2010
Posts: 10
Thomp,

you write on 2010-03-08 12:54:45 this:

' ... . You can setup the Host Container message handler functions inside the
' Initialize or DocReady events.

Can you show me the code for VB6 to get this informations from my embetet pdf-document?
In my pdf-document is an butten to send message "this.hostContainer.postMessage(aMessage);", but there is no event in the sub Acro1_OnMessage()

thanks for your help
Ralf
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Please post this to a new thread

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script