javascript: Is there a way to get the view rotation?  SOLVED

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
Mathew
User
Posts: 188
Joined: Thu Jun 19, 2014 7:30 pm

javascript: Is there a way to get the view rotation?

Post by Mathew »

When a page is actually rotated, we can getPageRotation() from the document object for each page: But if the view is rotated with the buttons on the bottom of the screen, I can't find any function or property that lists that rotation, or provides a reliable clue about it. I saw in the adobe documentation they have an undocumented function Matrix2D.fromRotated() that tries to figure it out from Media and Crop box coordinates, but in my testing it's unreliable.

Isn't the view rotation a property of the document similar to .zoom? Is there such a property, or if not, can Tracker add one? Without this, it's impossible to know where "left" or "top" is from javascript.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17765
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: javascript: Is there a way to get the view rotation?

Post by Tracker Supp-Stefan »

Hello Mathew,

What are you trying to make this JS do?
The 'view rotation' is just a visual appearance change, and does not really affect the contents of the pages, so if you need to e.g. move content from one page to another - the view rotation would have affected them all and not have an effect on another operation.

There are methods in the no longer available for sale Editor SDK that can get and set the view rotation - but those are UI settings, and not really ones that you can access from inside the PDF file with JS.

Kind regards,
Stefan
Mathew
User
Posts: 188
Joined: Thu Jun 19, 2014 7:30 pm

Re: javascript: Is there a way to get the view rotation?

Post by Mathew »

Hi Stefan,

My case is simply that I want to be able to have a dialog box for a script that mirrors markup, and be able to say "mirror horizontally". If I don't know the view rotation as well as the page rotation, I cannot know what is "horizontal" within the script.

Actually PDF x-change also has problems with this with the "transform" and "duplicate" tools, as well as with "resize pages..." tool. (ie If the view is rotated 90 degrees left, the horizontal offset in Duplicate is actually down).
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8371
Joined: Wed Jan 03, 2018 6:52 pm

Re: javascript: Is there a way to get the view rotation?

Post by TrackerSupp-Daniel »

Hello, Mathew

I see, for clarity sake there are two different ways to rotate pages.
~"Rotate View" is, as stefan mentioned not something which has any effect on the document or commands applied to it. This means that if you have the "view" rotated 90 degrees, using a "Flip horzontal" command will cause the object to flip horzontally based on the documents original orientation (IE it will move veritcally from your current perspective). There is no way to detect that through JS that I am aware of, since it happens outside the document context, and is not something defined via the PDF specification (as it does not actually affect or ever get embedded into the PDF file).
~"Rotate page" is the option which will directly modify the content of the document, it will change the "rotation" property of the pages, and will cause features like the "flip horizontal" to work differently. In this case, if you us the "flip horizontal on a comment before or after using the "rotate page" command, the object will always be flipped horizontally from your perspective.

I hope this helps to explain the differences between these two functions and their uses.

Kind regards,
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 188
Joined: Thu Jun 19, 2014 7:30 pm

Re: javascript: Is there a way to get the view rotation?

Post by Mathew »

Daniel,
The doc object has a .zoom property that reports the current view zoom. Is that saved with the document? Can Tracker add a .pageViewRotation (for example) property to the .viewState object, even though it's not documented in the adobe api reference?

I guess what I'm getting at is: Is PDF-xchange bound to some standard that prevents you from adding a property that would make a lot of tools be a lot more user-friendly?
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: javascript: Is there a way to get the view rotation?  SOLVED

Post by Ivan - Tracker Software »

added viewState.pageViewRotation in the next major build.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Mathew
User
Posts: 188
Joined: Thu Jun 19, 2014 7:30 pm

Re: javascript: Is there a way to get the view rotation?

Post by Mathew »

:)
User avatar
Paul - Tracker Supp
Site Admin
Posts: 6813
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

javascript: Is there a way to get the view rotation?

Post by Paul - Tracker Supp »

:)
Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
Mathew
User
Posts: 188
Joined: Thu Jun 19, 2014 7:30 pm

Re: javascript: Is there a way to get the view rotation?

Post by Mathew »

It's in v10.0... Thank you!
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17765
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

javascript: Is there a way to get the view rotation?

Post by Tracker Supp-Stefan »

:)
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: javascript: Is there a way to get the view rotation?

Post by Ivan - Tracker Software »

Actually, there is a way to do that:

Code: Select all

viewState.pageViewRotation
The `viewState` object is implementation-defined and using its properties makes the code non-portable to other PDF apps.
The best way would be to check which app is in use (I believe there was a topic on the forum about that).
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Post Reply