8 Replies Latest reply on Oct 1, 2008 2:46 PM by Patrick Leckey

    How to scroll to bookmark when document opens

      Does anyone know an approach that can be used to scroll to a bookmark in a document when the document is opened?

      I am looking for a javascript solution, not passing arguments on the command-line or querystring.

      Thanks very much for any assistance. Mike
        • 1. Re: How to scroll to bookmark when document opens
          Level 1
          Try the openDoc() method with the cDest parameter.

          app.openDoc({cPath: "/c/temp/myDoc.pdf, cDest: "myDest"});

          Sabian
          • 2. Re: How to scroll to bookmark when document opens
            Level 1
            That is interesting but I'm constrained in the following way:

            I am delivering a PDF down to a browser in response to a browser request. So the doc is already coming down and I won't have a chance to explicitly open any document.

            What I want is that there is some Acrobat javascript inside the PDF that will start running when the doc opens. There is an app/init event that fires but I don't know how to hook into it and I also don't know how to embed the javascript into the PDF.

            Once I can get some javascript running when the doc opens I assume there are easy javascript calls to cause the jump to a bookmark.

            -Mike
            • 3. Re: How to scroll to bookmark when document opens
              Patrick Leckey Level 3
              Open a document in Acrobat.

              Advanced > Document Processing > Document JavaScripts
              Enter a name like "My Open Action" and click Add...
              Delete the empty function it creates and enter your script in this window.
              Save and close the document.

              That script will now run when the document is opened.
              • 4. Re: How to scroll to bookmark when document opens
                George_Johnson MVP & Adobe Community Professional
                Are you saying that you want the document to always open to a particular page (destination) whenever it is opened?

                George
                • 5. Re: How to scroll to bookmark when document opens
                  Level 1
                  Yes, I need to go right to a named destination or bookmark when the document opens. I don't need to go to a page number.

                  - Mike
                  • 6. Re: How to scroll to bookmark when document opens
                    Level 1
                    OK, that was good - getting there - thanks.

                    The thing is that I am building the PDF server-side so I need to know what to insert into the PDF to cause the javascript to run.

                    I know that complicates things but I am talking about a PDF generator that uses iText to create PDFs. So what I am really talking about is what do I have to code using Itext to cause my javascript to start running when the doc opens?

                    -Mike
                    • 7. Re: How to scroll to bookmark when document opens
                      gkaiseril MVP & Adobe Community Professional
                      If you have bookmarks, you can use the following document level scripts with versions 5 and above for Reader/Acrobat:

                      // Document-level or folder-level JavaScript.
                      function searchBookmarks(bkm, nLevel, bkmName)
                      {
                      if ( bkm.name == bkmName ) return bkm;
                      if (bkm.children != null) {
                      for (var i = 0; i < bkm.children.length; i++)
                      {
                      var bkMark = searchBookmarks(
                      bkm.children[i], nLevel + 1, bkmName);
                      if ( bkMark != null ) break;
                      }
                      return bkMark;
                      }
                      return null;
                      }

                      function exeOpenBM(bkmName) {
                      var bkm = searchBookmarks(this.bookmarkRoot, 0, 'Warning Category Summaries' );
                      if ( bkm != null ) bkm.execute();
                      else app.alert('Bookmark not found');
                      return;
                      }

                      exeOpenBM('Bookmark Name');

                      For a named destination the following document level script can be used:

                      this.gotoNamedDest('Destination Name');
                      • 8. Re: How to scroll to bookmark when document opens
                        Patrick Leckey Level 3
                        > The thing is that I am building the PDF server-side so I need to know what to insert into the PDF to cause the javascript to run.

                        Use an FDF with an /After action that points to a stream of JS text. That way when the PDF opens, it will run the JS in the FDF without you needing to embed the JS in the PDF.