5 Replies Latest reply on Nov 29, 2009 9:06 PM by MyCodeProblem

    How do I dynamically create a hyperlink in Indesign with vb

    MyCodeProblem

      Hi, does anyone know how to create a dynamic link to Indesign with vb? I'm coding a catalog from Access database with images and would like to make an "Enlarge image" hyperlink while generating the page. Somehow I seem to have no luck in my code. Thanks for any suggestions.

        • 1. Re: How do I dynamically create a hyperlink in Indesign with vb
          [Jongware] Most Valuable Participant

          Scripts in InDesign, whether javascript or visual basic, don't work like the ones in a web page. It's possible to write a script that enlarges an image, but you cannot "embed" the script into your InDesign document. Rather, when you run it, it will enlarge the image in your document -- in InDesign. Unless you are planning to distribute your InDesign document (and the script, separately), that won't work.

           

          What you could do is create a hyperlink to another page, showing the larger image, or try a combo of button and the image on an invisible layer. Nevertheless, you'd better examine first how your are going to send out the file to your readers. PDF?

          • 2. Re: How do I dynamically create a hyperlink in Indesign with vb
            MyCodeProblem Level 1
            It looks like I need to clear my questinon a little bit. I will create an Indesign CS4 file from MS Access reading product info from database and then export the Indesign CS4 file to an e-magazine (.swf format) . So what I really want to do is as follows: when the user opens the magazine in a web browser and clicks the product image, a bigger image will open. So I need to code a hyperlink to a picture at the same time that it's placed into Indesign page. The same thing that can be done in Indesign by hand using Interactivate/New Hyperlink. Hope this clears my problem?
            • 3. Re: How do I dynamically create a hyperlink in Indesign with vb
              Max Dunn Level 1

              Here's a JavaScript example:

               

              var myDocument = app.documents.item(0);
              with(myDocument.pages.item(0)){
              //Get a reference to the text frame.
              var myTextFrame = textFrames.item(0);
              var myParagraph = myTextFrame.paragraphs.item(0);
              myHyperlinkURL = myDocument.hyperlinkURLDestinations.add("http://www.publishingsilicon.com");
              myHyperlinkSource = myDocument.hyperlinkTextSources.add(myParagraph);
              myHyperlink = myDocument.hyperlinks.add(myHyperlinkSource,myHyperlinkURL);
              myHyperlink.visible=false;
              }

               

              This assumes a text frame exists with some text in it, and that when you export the PDF you either check Include\hyperlinks in the PDF Export dialogue, or do the equivalent with code if exporting programmatically.

               

              Let me know if you need this translated to VB, and we'll see if I can remember... :-)

               

              Thanks,

               

              Max

              • 4. Re: How do I dynamically create a hyperlink in Indesign with vb
                MyCodeProblem Level 1

                Hi Max,

                 

                thank you so much for your help! I'll try myself for a while and in case I

                don't succeed I'll turn to you.

                 

                Have a nice day!

                • 5. Re: How do I dynamically create a hyperlink in Indesign with vb
                  MyCodeProblem Level 1

                  As simple as it sounds to create hyperlinks with VB into Indesign CS4 it really took time and effort to finally

                • come up with the solution. With the kind help of  Max Dunn an old InDesign scripting bug with VB was discovered responsible for this. But if you split the job into two parts it can be done.
                • First make the document without hyperlinks in VB by putting the URLs in script labels on each graphic frame. Then in Indesing run a post-processing script in JavaScript that iterates through the graphic frames, and for each, if it has a script label, set that as the URL for hyperlink.
                •  

                  Here is how I did it in Indesign.

                  var myDocument = app.documents.item(0);

                   

                  for(var myCounter = myDocument.rectangles.length-1; myCounter >= 0; myCounter --){
                  alert(myCounter)
                  var myRectangle = myDocument.rectangles.item(myCounter);
                  var myLabel = myDocument.rectangles.item(myCounter).label;

                  try{
                  myHyperlinkURL = myDocument.hyperlinkURLDestinations.add(myLabel);
                  myHyperlinkSource = myDocument.hyperlinkPageItemSources.add(myRectangle);
                  myHyperlink=myDocument.hyperlinks.add(myHyperlinkSource,myHyperlinkURL);
                  myHyperlink.visible=false;
                  }
                  catch(myError){
                  }
                  }