Skip to main content
Raymond_Ford
Participating Frequently
Feb 26, 2019 3:56 PM UTC
Answered

Getting Preferences>Page Display>Resolution using Javascript

I have a pdf doc that when the user clicks a button, the document scales and scrolls both vertically and horizontally to a certain point inside the pdf. I need to get the user's Preference>Page Display> Resolution to ensure the user is navigated to the correct point in the pdf. How do i get that property using Javascript?

This topic is closed to new replies. Start a new post to keep the conversation going.
Thom Parker
Thom ParkerCorrect answer
Community Expert
Feb 26, 2019 5:01 PM UTC

While this property is not directly available, there are some things you can do to find the resolution.

Here are the steps for a script to follow.

1. save the current viewState: 

          var vsOrig = this.viewState.toSource();

2. Set the zoom type to FitH.  Save the zoom level.

3. Set the zoom type to FitV. Save the zoom level.

4. Reset the viewSate.

     this.viewState = eval(vsOrig);

Now you have proportionality factors between the current zoom and the full width and height of the document. This gives you enough information to calculate the portion of a document page being shown so you can set the page offsets (scroll) exactly.

Its all worked out, calculations and the code, here (but it's only available to site members):

Scripts for Navigating to a specific document location

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often

2 replies

Bernd Alheit
Community Expert
Community Expert
Feb 26, 2019 4:02 PM UTC

You can't access this property with Javascript.

Translate
Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
Feb 26, 2019 5:01 PM UTC

While this property is not directly available, there are some things you can do to find the resolution.

Here are the steps for a script to follow.

1. save the current viewState: 

          var vsOrig = this.viewState.toSource();

2. Set the zoom type to FitH.  Save the zoom level.

3. Set the zoom type to FitV. Save the zoom level.

4. Reset the viewSate.

     this.viewState = eval(vsOrig);

Now you have proportionality factors between the current zoom and the full width and height of the document. This gives you enough information to calculate the portion of a document page being shown so you can set the page offsets (scroll) exactly.

Its all worked out, calculations and the code, here (but it's only available to site members):

Scripts for Navigating to a specific document location

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often