Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

doc.pageWindowRect and doc.media are undefined in Acrobat Javascript

New Here ,
Sep 29, 2020 Sep 29, 2020

I am trying to use the doc.pageWindowRect information as part of some code I am writing using the Adobe Acrobat Javascript API.

 

I originally found that doc.pageWindowRect was undefined, and through various posts on this forum, found that I needed to activate the media extension first, by running something like

console.println(this.media);

 Normally this prints something like:

[object DocMedia]

but on some computers used by our client, this just prints 'undefined' instead. It seems that having this.media undefined means that doc.pageWindowRect will stay undefined too.

 

Does anyone know how to make sure this.media is defined, and thus enable doc.pageWindowRect? Or any other way of getting hold of the doc.pageWindowRect information?

 

I wondered if there might be a delay in activating the media extension, and have tried repeatedly running code to display this.media and doc.pageWindowRect using app.setInterval, but even after waiting for a couple of minutes, they are still not defined.

 

Could this be related to the configuration of our client's Acrobat install? It seems to work fine on most other machines that we've tested it on, but there is definitely some sort of problem here.

 

Any help would be much appreciated.

 

Thanks,

 

Robin

TOPICS
Acrobat SDK and JavaScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 29, 2020 Sep 29, 2020

Does this happen with a specific version of Acrobat? Or maybe on a specific OS version?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 29, 2020 Sep 29, 2020

Thanks for the response.

 

They're using an older version of Adobe Reader to view the document (due to security requirements) - their app.viewerVersion is 17.01130171, and they're using Windows 7.

 

However, we've installed that version on a Windows machine and can't reproduce the error - it works fine for us.

 

Do you know if there are any preferences settings that could affect whether this.media or doc.pageWindowRect are available? Or any other 'best guess' ideas as to why these might be undefined?

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 29, 2020 Sep 29, 2020

How are you running this code, exactly? In what context?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2020 Sep 30, 2020

At the moment I'm just trying to print out the values of this.media and this.pageWindowRect in a Document Javascript that runs on document load.

 

The Javascript code I'm using for debugging is below - it prints out the debugging information every 5 seconds using app.setInterval, and then stops after 20 iterations. When run on most computers we get output like this, showing values for all the objects straight away (from iteration 0):

Debug info, iteration = 0
viewerVersion = 20.01220048
this.media object = [object DocMedia]
app.media object = [object AppMedia]
doc.pageWindowRect = 63,128,1016,731

However, when run on the client's computer, we get output like this:

Debug info, iteration = 20
viewerVersion = 17.01130171
this.media object = undefined
app.media object = [object AppMedia]
doc.pageWindowRect = undefined

showing a lot of things undefined even by the time we reach iteration 20 (around 1.5 minutes after load).

 

The code I'm using is below (the deliberate error bit is to force the debug window to appear in Adobe Reader by forcing an exception to be raised):

var debugTimer = null;
var debugPrintIteration = 0;

function printDebugInfo() {
    console.println("Debug info, iteration = " + debugPrintIteration);
    console.println("viewerVersion = " + app.viewerVersion);
    console.println("this.media object = " + this.media);
    console.println("app.media object = " + app.media);
    console.println("doc.pageWindowRect = " + this.pageWindowRect);
    console.println("-------------------");
    debugPrintIteration += 1;

    if (debugPrintIteration > 20) {
        app.clearInterval(debugTimer);
    }
}

// Debugging info
console.println("Opened document")
printDebugInfo();

debugTimer = app.setInterval("printDebugInfo();", 5000)


console.println("Deliberate error: " + this.blah.toSource());

 If you'd like to look at a full example PDF, then you can download my debug example from http://rtwilson.com/downloads/debug_js_for_forum.pdf

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 30, 2020 Sep 30, 2020

A weird thought: does this happen if you have already opened the Acrobat Reader app? I'm wondering about slow startup of these components. Also: check the list of installed plug-ins in the Help menu.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2020 Sep 30, 2020

Sometimes it seems like opening the app first helps - but I'd have thought that the investigation I've done using a timer to print out the values of this.media and this.pageWindowRect would show up any delay in loading the components. The timer runs for over 1.5 minutes, and at the end of that time the values are still showing up as undefined.

 

I'll ask our clients to check their installed plugins list.

 

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2020 Sep 30, 2020

I'm getting strange results with this object, too. Sometimes it works, other times it doesn't. And when it fails, it seems to also affect other files that otherwise would have worked... Seems not to be too stable.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2020 Sep 30, 2020

That's really interesting to hear - thanks. We haven't been able to reproduce the errors on our system, so it's good to hear that someone else can reproduce them - even if they seem to be rather unstable. Our clients have mentioned that occasionally it has seemed to work, but it seems to be semi-random and sometimes one file works but only when opened next to another file - or other strange things like that.

 

Are you using the latest version of Reader? We've tried with the latest version and the version our clients have been using, and haven't managed to reproduce it.

 

And was this testing with the file I sent, or some tests you created yourself?

 

I can't see anything else in my file that would be causing it - that is literally the only Javascript in the file (I removed a load of other stuff that I was using in case it was affecting it).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2020 Sep 30, 2020
LATEST

No, I'm using an older version (XI) of both Reader and Acrobat, and on files I created myself.

I can't reproduce it consistently, though. Sometimes it works, other times it doesn't. There doesn't seem to be much rhyme or reason behind it. I also ran the code from various contexts, like the console, a doc-level script, a button, etc. I suggest reporting it to Adobe as a bug, although bugs that can't be reproduced easily are very difficult to report (and to fix)... You can do it from here: https://www.adobe.com/products/wishform.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines