4 Replies Latest reply on Jan 24, 2013 4:15 PM by romanobstuder

    Hyperlink to a page

    romanobstuder Level 1

      Hi all

      I am trying to link all my images in a document.

      If I recognize the filename and it is a logo (only a limited logos are present) I link to the URL

       

      All others must link to a given page number.

       

      The first part works. But I can not figure out how to make the link to a page...

       

       

           case "cat 22m95y v1.eps":       

                  var myHyperLinkeFrame = myFrame.parent.textFrames.add(myLabelLayer2, undefined, undefined,{geometricBounds : myGreyBoxBounds});

                  myHyperlinkURL = myDocument.hyperlinkURLDestinations.add("www.catfootwear.com");

                  myHyperlinkSource = myDocument.hyperlinkPageItemSources.add(myHyperLinkeFrame);

                  myHyperlink=myDocument.hyperlinks.add(myHyperlinkSource,myHyperlinkURL );

                  myHyperlink.visible=true;                                 

          break;

       

       

          default:

                  $.writeln ("myImageJumperPage " + myImageJumperPage );

                  $.writeln ("myImageJumperPage " + Number (myImageJumperPage) );

                  var bla = Number (myImageJumperPage) ;

                  $.writeln ("bla " + bla);

                  var myHyperLinkeFrame = myFrame.parent.textFrames.add(myLabelLayer2, undefined, undefined,{geometricBounds : myGreyBoxBounds});

                  myHyperlinkPage = myDocument.hyperlinkPageDestinations.add();

                  myHyperlinkPage.destinationPage.pageNumber = myImageJumperPage;

        

                  myHyperlinkSource = myDocument.hyperlinkPageItemSources.add(myHyperLinkeFrame);

                  myHyperlink=myDocument.hyperlinks.add(myHyperlinkSource, myHyperlinkPage);

                  myHyperlink.visible=true;   

         

             }

       

       

       

      Any hins appreciated

      Romano

        • 1. Re: Hyperlink to a page
          romanobstuder Level 1

          should add

           

                      myHyperlinkPage.destinationPage.pageNumber = myImageJumperPage;

           

           

           

          this is where things go wrong...

          • 2. Re: Hyperlink to a page
            romanobstuder Level 1

            myHyperlinkPage.destinationPage = "2";

             

            I also tried this but again no go

            • 3. Re: Hyperlink to a page
              -hans- Level 4

              Hi,

               

              All others must link to a given page number.

              it expects a whole reference.

              For example:

              myHyperlinkPage.destinationPage = app.activeDocument.pages.item(0)

              • 4. Re: Hyperlink to a page
                romanobstuder Level 1

                OK I get it the reference to a page does not work based on a number as in go to page 10

                Needed to create the reference in "page" terms first.

                 

                            var destPage = myDocument.pages.itemByName(myImageJumperPage.toString());

                 

                This line changes (type cast) the number to a string, then finds the page with that (String)Name and creates a reference.

                I guess this could be coded in a more direct way, but I am happy.

                The code does the job

                 

                Thanks for your help Hans

                 

                 

                 

                 

                    case "cat 22m95y v1.eps":       

                            $.writeln ("Found a logo, jump to website 2");

                            var myHyperLinkeFrame = myFrame.parent.textFrames.add(myLabelLayer2, undefined, undefined,{geometricBounds : myGreyBoxBounds});

                            var myHyperlinkURL = myDocument.hyperlinkURLDestinations.add("www.catfootwear.com");

                            var myHyperlinkSource = myDocument.hyperlinkPageItemSources.add(myHyperLinkeFrame);

                            var myHyperlink = myDocument.hyperlinks.add(myHyperlinkSource,myHyperlinkURL );

                            myHyperlink.visible = true;                                 

                    break;

                 

                 

                    default:

                            $.writeln ("Found any image, create link to the price list on page: " + myImageJumperPage );

                            var myHyperLinkeFrame = myFrame.parent.textFrames.add(myLabelLayer2, undefined, undefined,{geometricBounds : myGreyBoxBounds});

                            var destPage = myDocument.pages.itemByName(myImageJumperPage.toString());

                            var myHyperlinkDestination = myMakeHyperlinkDestination(destPage, myDocument);            

                  

                            var myHyperlinkSource = myDocument.hyperlinkPageItemSources.add(myHyperLinkeFrame);

                            var myHyperlink = myDocument.hyperlinks.add(myHyperlinkSource, myHyperlinkDestination);

                            myHyperlink.visible = true;   

                    }    

                 

                 

                 

                function myMakeHyperlinkDestination(myDestPage, myDocument){

                    //If the hyperlink destination already exists, use it;

                    //if it doesn't, then create it.

                    try{

                        var myHyperlinkDestination = myDocument.hyperlinkDestinations.item(myDestPage);

                        myHyperlinkDestination.name;

                    }

                    catch(myError){

                        myHyperlinkDestination = myDocument.hyperlinkPageDestinations.add(myDestPage);

                        myHyperlinkDestination.destinationPage = myDestPage;

                    }

                    //myHyperlinkDestination.name = myDestPage.name;

                    //Set other hyperlink properties here, if necessary.

                    return myHyperlinkDestination;

                }