3 Replies Latest reply on May 28, 2013 2:07 AM by Peter Kahrel

    Doubt hyperlink Page Destination

    BEGINNER_X Level 3

      Hi Script Legends,


      I am entirely new for hyperlink concept.



      In the active document Hyperlink having "Link to Page" property. My requirement want to check the destination page.

      Suppose that page should be blank page then the hyperlink want to be delete.





      Using forum I try the below script:


      var myDoc = app.activeDocument

      //~ var myHyperlink = myDoc.hyperlinks.everyItem().getElements()

      //~ alert(myHyperlink.length)


      var myPageDestination = myDoc.hyperlinkPageDestinations.everyItem().getElements()

      alert("myPageDestination:" + myPageDestination.length)


      var myPageItems = myDoc.allPageItems

      alert("myPageItems:" + myPageItems)



      for(j=0; j<myPageDestination.length; j++)


          if(myPageDestination[j].pages[0].allPageItems == 0)







      Could anyone please rewrite my program. It should be very helpful for me.


      Thanks in advance


        • 1. Re: Doubt hyperlink Page Destination
          Peter Kahrel Adobe Community Professional & MVP

          Change this:


          if(myPageDestination[j].pages[0].allPageItems == 0)


          to this:


          if(myPageDestination[j].pages[0].allPageItems.length == 0)


          but you might as well use this:


          if(myPageDestination[j].pages[0].pageItems.length == 0)


          pageItems is a collection on page items at the top level, i.e. groups are seen as such, you don't get the items in groups. allPageItems is an array of all page items, including all grouped items.



          • 2. Re: Doubt hyperlink Page Destination
            Laubender Adobe Community Professional & MVP

            @Peter – hm, I think myPagedestination[j].pages[0] cannot work, because hyperlinkPageDestinations have no page property…


            There is a destinationPage property for that purpose.


            And if we remove all hyperlinkPageDestinations whose destination pages have no page items, wouldn't that leave the corresponding hyperlinks intact? With a destination property that is null?


            If we'd like to remove also ALL hyperlinks with destination:null, we could use this code:


            var d=app.documents[0];
            $.writeln("Hyperlink length BEFORE: "+d.hyperlinks.length);
            //Remove all hyperlinkPageDestinations, if there are no pageItems on the page:
            for(var n=d.hyperlinkPageDestinations.length-1;n>=0;n--){
                if(d.hyperlinkPageDestinations[n].destinationPage.allPageItems.length === 0){
            //So that we removed the hyperlinkPageDestinations, the corresponding hyperlinks are still there.
            //Should they also be removed?
            //Generally: schould ALL hyperlinks be removed without destinations?
            //(Not ONLY the ones we cared about as we removed their destinations in the loop above, but really ALL without destinations)
            //If so, we can run this loop:
            for(var n=d.hyperlinks.length-1;n>=0;n--){
                if(d.hyperlinks[n].destination === null){
            $.writeln("Hyperlink length AFTER: "+d.hyperlinks.length);



            But this is debatable…


            To get this really right* we should:


            1. Collect all the documentOffset values for all pages without any page items
            2. Loop through all the hyperlinks of the document in reverse order
            3. Check, if the destination is of type "HyperlinkPageDestination" with something like that:

            if(myHyperlink.destination.constructor.name === "HyperlinkPageDestination")

            If that is true, check, if the destinationPage.documentOffset is in the array with the empty pages and if yes, remove the hyperlink.


            * only if my assumption is right, that not only the found hyperlinkPageDestination should be removed, but also all corresponding hyperlinks.



            • 3. Re: Doubt hyperlink Page Destination
              Peter Kahrel Adobe Community Professional & MVP

              Thanks, Uwe. I simply looked no further than "pages[0].allPageItems == 0" and 'corrected' that. Indeed hyperlinkPageDestinations don't have a page property, but they do have a destinationPage property, so this should work:


              if(myPageDestination[j].destinationPage.allPageItems.length == 0)