7 Replies Latest reply on Feb 24, 2012 2:19 PM by technothrakon

    Missing http after Convert URL to hyperlink in CS5.5

    Jon WorldAccent Level 1

      I am adding hyperlinks to a long document using InDesign CS5.5's "Convert URLs to hyperlinks"

       

      This works fairly well, but I am having a problem with URLs that don't start with http or www as part of the text (ie with example.com as opposed to www.example.com). The hyperlinks produced from these do not get an http:// inserted. So when you produce an interactive PDF, these links act as relative links and are prefaced by the file path to the PDF.

       

      Example:

       

      In the text is a website example.com/details. When you run "Convert URL to hyperlink", this gets a hyperlink created with an URL of example.com/details. I then export to an interactive PDF on my disk Jobs/project123/PDFs. When you click on this link in Acrobat, it attempts to open

      file:///Volumes/Jobs/project123/PDFs/example.com/details

      rather than

      http://example.com/details

       

      Is there a way to make InDesign automatically insert the required http:// in the hyperlink destination to make this link absolute, or must I edit each destination by hand?

        • 1. Re: Missing http after Convert URL to hyperlink in CS5.5
          John Hawkinson Level 5

          I would say this is certainly a bug -- InDesign should not produce an URL in a hyperlink destination. If it detects it as a destination, it should do whatever is necessary.

           

          Anyhow, this is easy enough to fix via a script (untested)t. Try this:

           

          var
              i,
              hls=app.activeDocument.hyperlinkURLDestinations;
          for (i=0; i<hls.length; i++) {
              if (!hls[i].match('://')) {
                  hls[i] = 'http://' + hls[i];
              }
          }
          

           

          That is, loop over all the hyperlink destinations (hls) in the document, and check to see if each one does not contain ://. If so, prepend "http://" to it.

           

          Save the above as fixlinks.jsx and install per

          http://www.danrodney.com/scripts/directions-installingscripts.html.

          • 2. Re: Missing http after Convert URL to hyperlink in CS5.5
            Jon WorldAccent Level 1

            John,

             

            Thanks for your helpful reply.

             

            Sadly the script falls over (you did warn me it was untested) saying "hls[i].match is not a function". I can get it to run by sticking a toString() in there, but the hyperlink destinations don't seem to update. Although I can see what the script is doing, my knowledge of javascript was insufficiently detailed to press on further.

             

            However, what your idea did do is make me think about the problem from a different angle.

             

            Turns out there is script on InDesignSecrets that works a treat by allowing me to GREP the hyperlink destinations.
            http://indesignsecrets.com/batch-change-hyperlinks-across-a-whole-indesign-document.php

             

            Thanks again for the input

            • 3. Re: Missing http after Convert URL to hyperlink in CS5.5
              John Hawkinson Level 5

              Whoops!

               

              Some sort of internal brain cut-and-paste error there, I think. I tested more of it than that, but I made a consistent error writing it up.

              The problem is that, as you surmised, a hyperLinkURLDestination is not a string. The string inside it that we care about is the destinationURL property, so we have to use it, both in the test and in the modification:

               

                  if (!hls[i].destinationURL.match('://')) {
                      hls[i].destinationURL = 'http://' + hls[i].destinationURL;
              

               

              Editing the IDML isn't a script, but it's also a fine way to go! Whatever works best for you.I suspect the script is easier if it works for you...

              Let me know if the above works or doesn't (of course it needs to be wrapped in the surrounding lines from my first post).

              • 4. Re: Missing http after Convert URL to hyperlink in CS5.5
                Jon WorldAccent Level 1

                John, made that change and it fixes the problem perfectly. Thanks for your help!

                 

                I wonder if this isn't down to a difference in world views between InDesign and Acrobat. InDesign leans towards thinking all hyperlinks URLs must be absolute (and so doesn't add http, considering it implicit) whereas Acrobat allows for them to be relative (and so needs the http to be explicit). Either way, in effect it's a bug because the workflow from InDesign to Acrobat doesn't work how it should!

                 

                Anyway, problem solved, thanks again.

                 

                PS I should have been more clear in my link above, which is a script in the comments called ReplaceHyperlinkUrlValues which allowed you to GREP hyperlink destinations. But that is a sledgehammer to crack a nut compared to your elegant solution...

                • 5. Re: Missing http after Convert URL to hyperlink in CS5.5
                  technothrakon

                  This solution also worked for me.  For those not wanting to go through and piece together the complete script since the original one mentioned needs tweaking to work, it is:

                   

                  var

                      i,
                      hls=app.activeDocument.hyperlinkURLDestinations;
                  for (i=0; i    if (hls[i].destinationURL.match(/\s$/)) {      
                  hls[i].destinationURL = hls[i].destinationURL.replace(/\s*$/,"");  
                  }
                  }

                  • 6. Re: Missing http after Convert URL to hyperlink in CS5.5
                    daveslc

                    The scripts posted above don't seem to work.

                    They also don't deal with correctly linking email addresses. And lastly, this is a javascript, and needs the file extension .jsx

                    The bug in the program also converts lists to hyperlinks (e.g. 1. Header... 2. Header...). The script below doesn't address that.

                     

                    Try:

                     

                     

                    var

                        i;

                        hls=app.activeDocument.hyperlinkURLDestinations;

                    for (i=0; i<hls.length; i++) {

                        if (!hls[i].destinationURL.match('://') && (!hls[i].destinationURL.match('mailto'))) {

                            hls[i].destinationURL = 'http://' + hls[i].destinationURL;

                    }

                    }

                    • 7. Re: Missing http after Convert URL to hyperlink in CS5.5
                      technothrakon Level 1

                      Hi Daveslc -

                       

                      Sorry about that.  I don't think I meant to reply to this post when I posted before.

                       

                      Actually I was using a variation of a script that John Hawkinson posted that addressed an issue with carriage return characters being inadvertently inserted at the end of every hyperlink in InDesign... these carried over when exporting to PDF, making the links useless.  So the script I posted was actually to take out the carriage returns.

                       

                      Doesn't look like there's a way to edit my post, so I guess it will have to stand.  My bad!

                       

                      --AJ