4 Replies Latest reply on Dec 13, 2013 3:00 PM by Fondor1

    Scroll to and Focus/Center annotation in View

    Fondor1

      In an attempt to duplicate functionality that existed in Adobe 9, I am trying to make buttons that will jump to the next/previous annotation in relation to the currently selected annotation. I have all the code working up to moving the view precisely to the annotation location and centering on that comment.

       

      Workspace: Adobe Acrobat XI Professional running on Windows 7 64bit. Multipage Adobe Acrobat file open, with annotations (comments) dispersed throughout. One annotation is selected/in focus in the UI.

       

      Problem: My issue seems to be with the doc.scroll() method. I can jump to the page where the next/previous annotation lives, but then calling .scroll() on Rotated User Space coordinates derived from the annotation.rect does NOT center the view as the method description states in the documentation. Is this method somehow dependant upon the zoom level or doc layout that I am not aware of? Code in question is below:

       

          // nextComment is the annotation object I want to center on
          myDoc.pageNum = nextComment.page
      
          // Convert from Default User Space to Rotated User Spaec
          var m = (new Matrix2D).fromRotated(myDoc,0);
          m = m.invert();
          var nextCommentRect = m.transform(nextComment.rect);
      
          // Scroll the center of the view to the comment's top left corner
          myDoc.scroll(nextCommentRect[2], nextCommentRect[1]);
      
          // Open the comment popup
          nextComment.setProps({popupOpen: true});
      
      

       

      When running this code on a test PDF, the document does scroll but never to the right place. What is wrong here? Is there a better way to implement this functionality than my attempt here?

       

      I appreciate any help you can provide.

        • 1. Re: Scroll to and Focus/Center annotation in View
          try67 MVP & Adobe Community Professional

          Couple of issues:

          1. The second parameter of fromRotated needs to be the page in question, so the page where the annotation is located.

          2. As the nY parameter of scroll use the third object in the rect array, not the second. That would make the annotation visible when you scroll to it.

          3. Centering the view on the annotation will be difficult, as you need to take into consideration the zoom level, view setting, page size, and possibly even things like window size and resolution (the latter you can't actually know)...

          • 2. Re: Scroll to and Focus/Center annotation in View
            Fondor1 Level 1

            Thanks for your reply!

             

            1. I fixed the parameter of fromRotated to refer to the correct page. Thanks for that!

            2. I am confused about this comment. The third object of the Rect array is xur, is it not? Why would we be passing an x coordinate to the nY parameter of the scroll method?

            3. Centering the view is actually not entirely important, but certainly desired. At a minumum I expect to have the annotation in view but it doesn't have to be centered.

             

            My desired behavior can be duplicated by the following: when the comment sidepane is shown, one can click on any annotation and the view scrolls the document enough such that the annotation is completely visible (and keeps the current zoom level).

            • 3. Re: Scroll to and Focus/Center annotation in View
              try67 MVP & Adobe Community Professional

              2. Sorry, I meant the fourth item. Doing so will cause the annotation to be visible on the page. If you want, add a certain fixed margin to it, so it looks nicer.

              • 4. Re: Scroll to and Focus/Center annotation in View
                Fondor1 Level 1

                This is workable, thank you! I added a static buffer of +100 to each comment; for most pages that number seems to work out just fine. Not perfect, but it's much better than it was. Marked your reply as "Correct".