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

this.*WindowRect properties all undefined

efos
Registered: Jan 8 2009
Posts: 63

I'm trying to get pageWindowRect; made a button which does:

console.println(this.pageWindowRect)
console.println(this.docInnerWindowRect)
console.println(this.docOuterWindowRect)
console.println(this.appInnerWindowRect)
console.println(this.appOuterWindowRect)

and returns
undefined
undefined
undefined
undefined
undefined

the example code:
var coords = this.innerAppWindowRect;
console.println(coords.toSource())
// Possible output: [115, 154, 1307, 990]

returns
coords has no properties
8:AcroForm:dQuestionEOB05PC12a1:Annot1:MouseUp:Action1

Any ideas? Are these properties dead and buried?

Backstory: I have bookmarks where fields need to go. I want to get the Y value of the current viewstate to place a field relative to the top of the viewable area. eval(viewState.toSource()).pageViewY is based off some crazy number that goes over 1000 (while valid page coords max at ~792). viewState y values also use top as 0, where rect Y values use the bottom as 0.

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You need to get the properties correct and make sure you are using a version of Acrobat/Reader that can provide those properties.

console.println('viewer version number: ' + app.viewerVersion);if(app.viewerVersion < 6) {app.alert('The window rectangle properties are only available for version 6 or above', 0, 0);} else {console.println('pageWindowRect: ' + this.pageWindowRect);console.println('innerAppWindowRect: ' + this.innerAppWindowRect);console.println('outerDocWindowRect: ' + this.outerDocWindowRect);console.println('outerAppInnerWindowRect: ' + this.outerAppInnerWindowRect);console.println('outerDocWindowRect: ' + this.outerDocWindowRect);}
Quote:
viewer version number: 8.101
pageWindowRect: 300,216,1135,830
innerAppWindowRect: 0,46,1152,830
outerDocWindowRect: -4,186,1156,834
outerAppInnerWindowRect: undefined
outerDocWindowRect: -4,186,1156,834

true

George Kaiser

efos
Registered: Jan 8 2009
Posts: 63
gkaiseril wrote:
You need to get the properties correct
Oops. That's embarrassing, but the end result is the same:

viewer version number: 9.1pageWindowRect: undefinedinnerAppWindowRect: undefinedouterDocWindowRect: undefinedouterAppWindowRect: undefinedinnerDocWindowRect: undefined

I'm using 9.1 Pro, and I see that it sees that; I'm at a total loss here.
efos
Registered: Jan 8 2009
Posts: 63
Current kludge:
pageHeight = 792viewHeight = 1160 //(best guess as to the max Y value from viewState)startY = pageHeight-(((eval(this.viewState.toSource()).pageViewY/(this.zoom/100))/1160)*pageHeight)

It works, well enough for my purposes; but man. pageWindowRect[1] seems like the correct way to address this problem.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
With version 9 the documentation shows the use of the 'toSource()' method to convert the object to a string, [url=http://livedocs.adobe.com/acrobat_sdk/9/Acrobat9_HTMLHelp/wwhelp/wwhimpl/js/html/wwhelp.htm?href=JS_API_AcroJSChanges.89.1.php#1515776&accessible=true]innerAppWindowRect[/url].
if(app.viewerVersion < 6) {app.alert('The window rectangle properties are only available for version 6 or above', 0, 0);} else {console.println('viewer version number: ' + app.viewerVersion);console.println('pageWindowRect: ' + this.pageWindowRect.toSource());console.println('innerAppWindowRect: ' + this.innerAppWindowRect.toSource());console.println('outerDocWindowRect: ' + this.outerDocWindowRect.toSource());console.println('outerAppInnerWindowRect: ' + this.outerAppInnerWindowRect.toSource());console.println('outerDocWindowRect: ' + this.outerDocWindowRect.toSource());}

Now once you get these strings you will need to convert them to an array for further processing.

There is always something being changed by Adobe in the Acrobat JavaScript with each new product release.

George Kaiser

efos
Registered: Jan 8 2009
Posts: 63
The problem is that I don't get those strings to begin with, they're undefined. So calling .toSource() just results in a "x has no properties" error.

The documented properties have no value. I'm going to try and test this on an 8.1 system; maybe they completely changed this in 9/9.1

Edit: It works in 8.103 with the same PDF; so they clearly just changed something between the last js_api.pdf update and 9.1. Grumble.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Have you looked at the documentation for Acrobat JavaScript for version 9?

There have been a lot of changes in security, properties, methods, and how objects are being created with each new version of Acrobat/Reader, so one needs to check the new documentation when things no longer work.

See the link that I provided above.

George Kaiser

efos
Registered: Jan 8 2009
Posts: 63
gkaiseril wrote:
Have you looked at the documentation for Acrobat JavaScript for version 9?There have been a lot of changes in security, properties, methods, and how objects are being created with each new version of Acrobat/Reader, so one needs to check the new documentation when things no longer work.

See the link that I provided above.
Thanks, I did. Unfortunately it is identical to my offline reference in this regard.
rob cairns
Registered: Jun 29 2009
Posts: 8
Were you able to resolve this?

I have the same problem.
I am trying to upgrade code from Acrobat 6 to Acrobat9. I used pageWindowRect extensively, but now it says it is undefined.
None of the other windowRect properties work either.

On a related note, does anybody know how to get a PDF file of the Acrobat 9 Javascript reference manual? The HTML pages are terrible.
efos
Registered: Jan 8 2009
Posts: 63
I was not, I just worked around it. As to an offline 9.1 js API reference, I'm not sure. I've been using the 8.1 reference linked at the top of the forum; but I've been developing for 8.13 so I never noticed it's shortcomings. (Rich Media Annots being one of them)
rob cairns
Registered: Jun 29 2009
Posts: 8
Thanks for responding .
I'm sure it's security related, but I haven't the foggiest why.
If I find an answer I will be sure to post it.
chuck.williamson
Registered: Sep 1 2010
Posts: 3
Any solution to this problem yet? I was using the pageWindowRect property in acrobat 7 and 8 with no problem. Even the latest 9.2 still returns pageWindowRect as undefined although the javascript documentation lists pageWindowRect as a valid property.
rob cairns
Registered: Jun 29 2009
Posts: 8
pageWindowRect is part of the multimedia.api plugin that , in Acrobat 9.x, does not get loaded by default. As far as I know the only way to load that plugin is to actually have some media in the PDF file (but I am not 100% sure about that). Regardless I could not figure out how to force the plugin to load, so I abandoned using pageWindowRect.
Instead I used something similar to what efos wrote about in 2009-05-18 20:09:21 posting.
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
Rob's right, but it's easy to get it to load. For example:

console.println(this.media);
app.alert(innerAppWindowRect);
chuck.williamson
Registered: Sep 1 2010
Posts: 3
Thanks for the quick info. I see how this easily helps when you're executing the Javascript in the document, but I wasn't able to figure out how I can achieve this using C# and JSObject.

Here's what I was doing to get the page dimensions
object acroJSObject = acroPDDoc.GetJSObject();object[] screenRect = (object[])acroJSObject.GetType().InvokeMember("pageWindowRect", BindingFlags.GetProperty, null, acroJSObject, null);Rectangle pageRect = new Rectangle(Convert.ToInt32(screenRect[0]), Convert.ToInt32(screenRect[1]), Convert.ToInt32(screenRect[2]), Convert.ToInt32(screenRect[3]));

I've tried adding a line to instantiate the media object but it didn't help or I'm not doing it right.
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
Chuck,

You should be able to use the JSObject to execute that first line of code I showed, though I don't know how to do it in C#.
piffy
Registered: Apr 14 2011
Posts: 2
Hi Chuck,

I had the same issue in C#.
So I did not use invoking javascript but used their .net library.

AcroPDPage p = doc.AcquirePage(0);
AcroPoint pp = p.GetSize();

int a = pp.x;
int b = pp.y;


piffy
Registered: Apr 14 2011
Posts: 2
AcroPDDoc doc