5 Replies Latest reply on Mar 26, 2015 10:25 PM by gert verrept

    add hyperlink by script

    gert verrept Level 2

      Hi,

      Is it possible to add hyperlinks by javascript, so that they can be assigned later in the document? Let me explain my thoughts:

       

      hyperlink.jpg

      This screen shot shows a list of different docs (001 to 005) and the URL for the first document. I would like to make a hyperlink to all of them more automatically. Because the file is saved as 54K0504001.indd, I think it can be done.

      What I should need:

      1. a pop up with a question:"how many hyperlinks to make"

      2. depending on the answer, creating the new hyperlinks in the panel with the full URL (if the answer is 2, I should get 2 hyperlinks, http://www.dekamer.be/FLWB/PDF/54/0504/54K0504001.pdf and http://www.dekamer.be/FLWB/PDF/54/0504/54K0504002.pdf

        • 1. Re: add hyperlink by script
          gert verrept Level 2

          I made a little mistake: the screen shot shows a reference list (at the bottom of the fist page, all the other documents are listed). It's for this list I want to make a hyperlink.

          • 2. Re: add hyperlink by script
            Peter Kahrel Adobe Community Professional & MVP

            Gert,

             

            It's not clear what you mean by 'add hyperlinks by javascript, so that they can be assigned later in the document' -- not to me, anyway.

             

            And could you explain in more detail what the sources and the destinations of the hyperlinks are? You write 'if the answer is 2, I should get 2 hyperlinks, http://www.dekamer.be/FLWB/PDF/54/0504/54K0504001.pdf and http://www.dekamer.be/FLWB/PDF/54/0504/54K0504002.pdf'. The destinations are the two PDFs. And the sources? '001: Lorem Ipsum'?

             

            Peter

            • 3. Re: add hyperlink by script
              gert verrept Level 2

              We make parliamentary documents in Indesign (2014.2) and publish them in pdf format (www.dekamer.be). In this case (0504) we have a serie of 5 seperate docs. Each doc has refferences to the previous ones on his first page (so doc 005 has refferences to doc 004, 003 ,002 and 001), but no hyperlink (URL) are made. The "lorem ipsum" is the dummy text for "report, amendement ..." but is of no importance, just the 001, ... are.

              What I was thinking about, is having the hyperlinks (URL) "ready for use" in the hyperlinks panel, so that when we publish the document we can speed up the whole operation of creating new urls. When the exact URL is already in the panel, we just select the number 001 and assign it to the corresponding url (maybe named 001 too) in the panel and so on untill the last 00x.

              The destination is always pdf.  All hyperlinks start with http://www.dekamer.be/FLWB/PDF/54/ .  Per doc the number stays the same (0504), only the last part 001 changes....

              I add a screen shot of the first page from another doc.

              What the script (a java, no VB) should do is give me the possiblity to "prepare" the URLs so that they are ready in the dropdown menu of the hyperlink panel. The only thing is, we don't know in advance how many URLs we need. I thought a pop up would be the most easy way to solve that problem ("how many URLS have to be made? I the 0504 case I need 5 URLS named from 1 to 5). In the case below 23. I hope this explains it a bit better.

              page1.jpg

              • 4. Re: add hyperlink by script
                Peter Kahrel Adobe Community Professional & MVP

                Ok, clear. That looks simple enough:

                 

                main();
                
                function main() {
                    var num = prompt ('How many hyperlinks?', '1', 'Create hyperlinks');
                    if (num === null) {
                        exit();
                    }
                
                    function pad (n) {
                        return ('00'+n).slice(-3);
                    }
                
                    var base = 'http://www.dekamer.be/FLWB/PDF/54/0504/54K0504';
                    for (var i = 1; i <= num; i++) {
                        var hl = base+pad(i)+'.pdf';
                        app.documents[0].hyperlinkURLDestinations.add(hl, {name: hl});
                    }
                }
                

                 

                You could probably automate it completely, but that's more work.

                 

                Peter

                • 5. Re: add hyperlink by script
                  gert verrept Level 2

                  Peter,

                   

                  Works great. Thanks a lot. I just changed the line 13 so that it can be used for whatever document by spliting it up like this:

                  var base1 = 'http://www.dekamer.be/FLWB/PDF/54/';

                  var base2 = prompt ('doc number', '0000', 'Enter doc number');

                  var base = base1+base2+'/54K'+base2

                   

                  Gert