6 Replies Latest reply on Mar 7, 2013 5:36 AM by MarkWalsh

    Javascript equivalent of 'Go to page view'?

    MarkWalsh Level 4

      I have a PDF with several attached PDFs which I need to open. Several of them are opened with a button, which works fine using 'Go to page view' as their action. This works with Acrobat Pro or Reader in all tests I have tried. But, a few of the files have to open with a dropdown selection, which I have coded using the following in the 'validate' event of the dropdown menu:

       

          var oDoc = openDataObject(fileName);

           if (oDoc != null) {

             var filePath = oDoc.path;

              oDoc.closeDoc();

              try {

                  app.openDoc({cPath: filePath, bHidden: false});

              } catch (e) {

                  app.alert('Error in app.openDoc: ' + e.message);

              }

          }

       

      This works, but not in all cases. Is there a way to call the same 'Go to page view' command via javascript from the dropdown menu?

        • 1. Re: Javascript equivalent of 'Go to page view'?
          try67 MVP & Adobe Community Professional

          You can do this in a couple of ways.

          - If you have Named Destinations in your target file you can use the cDest parameter of openDoc to automatically jump to one of them when it is opened.

          - If you want to link to a page or a specific view state you will need to make sure that the file you're linking to is disclosed, and then the openDoc method will reuturn a doc object, which you could manipulate to do that (by setting the pageNum property, for example).

          • 2. Re: Javascript equivalent of 'Go to page view'?
            MarkWalsh Level 4

            Thanks, but I may not have represented my question accurately enough (sorry, been a long couple days with a corrupted PDF, defective USB media, and other issues on an unexpected deadline)

             

            I'd like to not use 'openDataObject' and 'openDoc' at all, since that's where the problems are occurring. I was hoping that there was a Javascript equivalent to the command I was using in the buttons so I could use that instead of the code above to open the attached PDF (I'm not as concerned with linking to a certain page; using the PDF's default open options is ok).

             

            I tried using a set of hidden buttons, setting their onFocus/onBlur action to the 'Go to page view', but there were issues with that (the parent PDF would always be re-activated right after the embedded PDF was opened)

             

            For now, I've recreated the popup options with a set of buttons, and that may do what I want, although the new version (which i believe is an improvement to the original with the popup) may not be approved by the client (my original suggestion was to change the layout of the piece to allow for the options as buttons instead of a popup, but I am not allowed to make those changes).

            • 3. Re: Javascript equivalent of 'Go to page view'?
              try67 MVP & Adobe Community Professional

              The answer is no, I'm afraid. Using JS you can only create JS actions.

              1 person found this helpful
              • 4. Re: Javascript equivalent of 'Go to page view'?
                MarkWalsh Level 4

                Thanks again.

                 

                One of the things I had looked for was a way to activate an existing link through JS, but the Link class only has one method 'setAction'.

                 

                I believe that the new version I have been working on replacing the dropdown with an array of buttons will do what I need to.

                 

                Appreciate the assistance.

                • 5. Re: Javascript equivalent of 'Go to page view'?
                  try67 MVP & Adobe Community Professional

                  Are you linking to just a page (by setting the pageNum property), or do you

                  need to link to a specific point in the page?

                  • 6. Re: Javascript equivalent of 'Go to page view'?
                    MarkWalsh Level 4

                    No, I'm just trying to open up the attachment to the first page @ fit page view. Essentially, I need to open an attached PDF from a dropdown once a choice is selected (via mouse click, or keyboard commit).

                     

                    The non-JS way I found to open an attachment is to use the 'Go to page view' action which does what I need. But this works only as an action, which is fine for the items which are opened via a button. The dropdown does not have a 'selection changed/committed' action, so I have to open the attachment via JS in the validate event, but the code I posted first was not working consistently. Perhaps I was doing something wrong, but at times it would work in Pro but not Reader, other times I got an error (invalid argument type) even though I copied the filename directly from the attached file, and verified that I was using the correct filename for the attachment.

                     

                    If there is a better solution that I am missing, I am open to any other suggestions.

                     

                    Thanks again.