Copy link to clipboard
Copied
I have experimented a lot using viewState function
this.viewState.toSource();
var refView = eval(viewState.toSource());
refView.pageViewZoom= 5;
refView.pageViewY = 1500;
refView.pageViewX = 800;
this.viewState = refView;
this.viewState.toSource();
but it is going haywire and is not able to focus on the page at the X and Y coordinates.
I have tried page scroll also and there is no description in the manual.
Your help is very much appreciated.
1 Correct answer
In that particular line of code, the x coord is 0, which scrolls to the left edge of the page.
Perhaps a better way to think of it is that you are not scrolling (or moving ) the page, but you are moving the viewport over the page. To see this in action, open the "page navigation" panel on the left side of the Acrobat window. The viewport is drawn over the thumbnail for the current page. As you zoom and scroll you can see the viewport change size and move.
Also keep in mind that the viewport
...Copy link to clipboard
Copied
To navigate to a particular page location you need to know more than is available in a single viewstate. For example, the pageViewX and pageViewY are in screen coordinates, not PDF page coordinates. They are measured from the top left corner of the view box to the top left corner of the page. So to scroll using the viewState you have to know the scaling between page coordinates and screen coordinates, and you have to know how much of the page is showing in the view box. To get this information you need to acquire the view state when the page width or height are known relative to the view box. This gives you the view box size and a starting point for calculating the scaling, i.e. the zoom level at which the full document size matches the view box in screen coordinates. From there the scaling between page coords and screen coords is proportional to the zoom level. So you can get coordinates in either system. Use the screen coords to navigate using the viewState, or use page coords to navigate using the scroll() function.
I worked all this out years ago and it's on the paid for page, with examples:
https://www.pdfscripting.com/public/DocumentNavigation.cfm
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thanks for your reply. I see those links are in the membership pages.
I don't use these scripting often. Is it possible to provide me the method only for this specific purpose of focusing to the page coordinates.
Thanks in advance
Copy link to clipboard
Copied
Explain what you are trying to accomplish.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
I am trying to create page link, which on clicking should go to another page with particular zoom and x , y coordinates.
This requires to be automated using JavaScript as I want to do it for several pages.
Copy link to clipboard
Copied
This is not a trivial problem. It takes a little geometry. I can tell you how to approach a solution, but coding it is up to you.
The easiest solution is to use the scroll() function. It places the upper left corner of the view box relative to the bottom left corner of the current page. The view box is what the user sees on the screen as a result of the current page, zoom, and scroll. You can see the view box on the Acrobat's pages panel. The values of the X and Y scroll positions are in standard Acrobat User Coordinates. Positions are given in points, where there are 72 points/inch. The "scroll()" function will not place the view box above or below the limits of the page if the page display is set to single page. But scrolling will cause page changes if the page display is set to continous. So, this scrolling scheme is a bit awkward in the vertical direction.
For example, to place the scroll box 2 inches from the top of the page you would need to know the height of the page. Say for example that the page is a standard 8.5(612pts) x 11(792pts) inches. The scroll code would be:
this.scroll(0, 792 - (2 * 72));
So a generic scroll to a specific page location is
this.scroll(x, PageHeight-y);
where x and y are in page coordinates.
But keep in mind that x and y above represent the edges of the scroll, they don't center on the coordinates. If x=72, the page is scrolled 1 inch to the right from the left edge. For centering you have to know the size of the view box at a particular zoom level. I pretty much explained the method for finding the view box in my first post.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Dear Thom Parker,
I know i am taking your time and this involves a lot of geometry..
i experimented with this "scroll" function line for various x and y values. I know the page dimensions using the getpageBox properties.
this.scroll(0, 792 - (2 * 72));
but this not behaving as expected as it is not moving in x or y direction for some values.
How do i get the screen view dimension using javascript. i tried "crop" properties but doesn't seem to be helping.
Copy link to clipboard
Copied
In that particular line of code, the x coord is 0, which scrolls to the left edge of the page.
Perhaps a better way to think of it is that you are not scrolling (or moving ) the page, but you are moving the viewport over the page. To see this in action, open the "page navigation" panel on the left side of the Acrobat window. The viewport is drawn over the thumbnail for the current page. As you zoom and scroll you can see the viewport change size and move.
Also keep in mind that the viewport will not scroll beyond it's limits. If the zoom is set to show the full page, then scrolling isn't possible. Scrolling only works when zoomed in enough to allow room for the viewport to move.
You'll be able to see how this works by observering the viewport in the page navigation window.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thanks. but it doesn't get in to me.. that a simple task of able to zoom to a page coordinate is so difficult.
The scroll is not working at all....
Thanks for your time
Copy link to clipboard
Copied
Dear Parker,
Thanks very much for your help. now with the pan and zoom window, i am able to better understand this scroll function.
Very helpful tip.
Copy link to clipboard
Copied
It always helps when you can see what's going on.
Good Luck!
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Create a Named Destination and use the gotoNamedDest method to jump to it.
Copy link to clipboard
Copied
Create a Named Destination and use the gotoNamedDest method to jump to it.
By try67
Easy method! But time consuming and difficult to maintain.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thanks for your reply.
Since i want to automate this process using javascript, i dont think there is a way to automatically create named destination using javascript. unless i missed something.
Copy link to clipboard
Copied
You are correct, there is no way to create named destinations with JavaScript. You need to workout the geometry.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thanks for your reply.
Since i want to automate this process using javascript, i dont think there is a way to automatically create named destination using javascript. unless i missed something.

