16 Replies Latest reply on Jul 18, 2013 9:43 AM by John Kriho

    Automating URLs of catalogue numbers in InDesign CS4

    Paul Hurd

      Hi,

       

      Anyone know if a script can be used to automate the creation of URLs based on catalogue numbers in a document? For instance, many of our data sheets, brochures, etc. have long lists of catalogue numbers on the back pages. We'd like to use these as links when exported as PDFs. Trouble is, there are so many, it would take forever to click on them all and create individual links.

       

      I've read here on the forums that someone was asking a similar question about using Character Style sheets to "tag" content to convert to URLs. We want to do the same, only append the catalogue number to a static URL. For instance, www.mycompany.com/catalogue/XXXX where XXXX is a catalogue number from the text that is in a certain character style. We'd want to then create a link using this URL on the catalogue number in the text.

       

      Thanks,

      Sintares

        • 1. Re: Automating URLs of catalogue numbers in InDesign CS4
          Haakenlid Level 3

          Paul Hurd wrote:

           

          Hi,

           

          Anyone know if a script can be used to automate the creation of URLs based on catalogue numbers in a document? For instance, many of our data sheets, brochures, etc. have long lists of catalogue numbers on the back pages. We'd like to use these as links when exported as PDFs. Trouble is, there are so many, it would take forever to click on them all and create individual links.

           

          I've read here on the forums that someone was asking a similar question about using Character Style sheets to "tag" content to convert to URLs. We want to do the same, only append the catalogue number to a static URL. For instance, www.mycompany.com/catalogue/XXXX where XXXX is a catalogue number from the text that is in a certain character style. We'd want to then create a link using this URL on the catalogue number in the text.

           

          Thanks,

          Sintares

           

          I find the hyperlink functionality in InDesign to be highly confusing, but I think this should do what you want:

           

          var myDoc = app.activeDocument;
          var myLinkStyle = myDoc.characterStyles.itemByName("link"); // the Character style of the links
          var myURL = "http://www.mycompany.com/catalogue/"; // url of your company
          var i, myLinks, myLink, mySource, myDestination;
          
          for (i = myDoc.hyperlinkTextSources.length-1; i >= 0; i--){
              mySource =  myDoc.hyperlinkTextSources[i];
              if (mySource.sourceText.appliedCharacterStyle == myLinkStyle){
                  mySource.remove(); // removes existing hyperlinks to avoid "double bookings"
              }
          }
          
          app.findGrepPreferences = null;
          app.findGrepPreferences.appliedCharacterStyle = myLinkStyle;
          myLinks = app.findGrep();
          
          for (i = 0; i < myLinks.length; i++){
             myLink = myLinks[i];
             mySource = myDoc.hyperlinkTextSources.add(myLink);
             myDestination = myDoc.hyperlinkURLDestinations.add(myURL + myLink.contents);
             myDoc.hyperlinks.add(mySource, myDestination);
          }
          
          
          • 2. Re: Automating URLs of catalogue numbers in InDesign CS4
            Paul Hurd Level 1

            This is great and works like a charm. Except now I realize that the URL we're adding the Catalogue Number to ends with "&cid=BIOS-S-EPDF-1276-1109-SP". It's some kind of tracking code. I've tried fidgeting with the script to add this after the Catalogue Number, but I've not been able to figure out how.

             

            As an aside, we are getting a request to tag other parts of our documents with links. I believe we can use scripting to bring in the information from the Excel file (as XML?) and have the script search for matching phrases in the document and tag them with the corresponding URL. Ambitious, I know. Anyone have experience with this?

             

            I've started learning more about JavaScript by taking a Lynda.com course and I bought Shirley Hopkins ExtendScript book. Any more ideas for getting started?

             

            Thanks

            • 3. Re: Automating URLs of catalogue numbers in InDesign CS4
              Pickory Level 3

              Hello Paul,

               

              Can't you just add your tracking stuff to the end of myLink

               

              Some thing like:

               

              for (i = 0; i < myLinks.length; i++){
                 myLink = myLinks[i];

               

              myLink = myLink + ""&cid=BIOS-S-EPDF-1276-1109-SP";


                 mySource = myDoc.hyperlinkTextSources.add(myLink);
                 myDestination = myDoc.hyperlinkURLDestinations.add(myURL + myLink.contents);
                 myDoc.hyperlinks.add(mySource, myDestination);
              }

              • 4. Re: Automating URLs of catalogue numbers in InDesign CS4
                Paul Hurd Level 1

                OK, so here's some more information. This is a proposal I wrote for this project. We're losing lots of hours manually inputting these URLs in PDFs for linking and tracking. Any help would be appreciated.

                 

                Background

                The creative services department of our corporation has been tasked with adding hyperlinks in PDF marketing documents that appear online and on sales associates' iPads. A majority of these links are catalogue numbers that will link to the corresponding pages on our corporate site where clients may get more information and/or order these products. In some cases, the amount of catalogue numbers is quite vast, as in the case of product selection guides or product line brochures. Adding these links “by hand” has proved to be time consuming and mistakes are made. An automated solution is needed.

                 

                Tagging information is added to each URL and is variable from document to document.

                Proposal

                Using JavaScript within the ExtendScript functionality of Adobe Indesign (currently using version CS4), create a script that takes information from a Microsoft Excel document and create hyperlinks for when the document is saved as a PDF.

                 

                Ideally, the script must take the information from the Excel file, marry it to the Indesign document and automate creating links when output as PDF. Realizing that solution may require steps outside of script such as, converting Excel file to XML, resolving data inconsistencies (i.e. variable column header information), and working in Adobe Acrobat to format required links in images (logos).
                 

                Data from a typical excel file for a sales flyer is represented below. In all instances, page numbers, link information (text, logo or image) and URL are given. This representative is from a smaller marketing piece and is only to show sample data.

                 

                Page #

                What to link

                Link

                1

                M logo

                http://www.millipore.com/?cid=BIOS-S-EPDF-1013-1110-SP

                1

                72620-1KIT

                http://www.merck-chemicals.com/life-science-research/novaquant-human-mitochondrial-to-nucl ear-dna-ratio-kit/EMD_BIO-72620/p_uuid?WT.mc_id=5USEN1168

                2

                72620-1KIT

                http://www.merck-chemicals.com/life-science-research/novaquant-human-mitochondrial-to-nucl ear-dna-ratio-kit/EMD_BIO-72620/p_uuid?WT.mc_id=5USEN1168

                2

                72621-1KIT

                http://www.merck-chemicals.com/life-science-research/novaquant-mouse-mitochondrial-to-nucl ear-ratio-kit/EMD_BIO-72621/p_uuid?WT.mc_id=5USEN1168

                2

                72625-1KIT

                http://www.merck-chemicals.com/life-science-research/novaquant-human-mitochondrial-biogene sis-kit/EMD_BIO-72625/p_xBqb.s1OF8gAAAEvOP9EJ50e?WT.mc_id=5USEN1168

                2

                72626-1KIT

                http://www.merck-chemicals.com/life-science-research/novaquant-mouse-mitochondrial-biogene sis-kit/EMD_BIO-72626/p_uuid?WT.mc_id=5USEN1168

                2

                72627-1Kit

                http://www.merck-chemicals.com/life-science-research/novaquant-human-oxidative-stress-ki t/EMD_BIO-72627/p_xBqb.s1OF8gAAAEvOP9EJ50e?WT.mc_id=5USEN1168

                2

                72628-1Kit

                http://www.merck-chemicals.com/life-science-research/novaquant-mouse-oxidative-stress-kit/ EMD_BIO-72628/p_uuid?WT.mc_id=5USEN1168

                2

                M logo

                http://www.millipore.com/?cid=BIOS-S-EPDF-1013-1110-SP

                2 - EM

                link: www.millipore.com/offices

                http://www.millipore.com/offices/cp3/officeshome&open&cid=BIOS-S-EPDF-1013-1110-SP

                2 - MM

                link: www.merckmillipore.com/offices

                http://www.millipore.com/offices/cp3/officeshome&open&cid=BIOS-S-EPDF-1013-1110-SP

                2 - EM

                Facebook logo / link EM

                http://www.facebook.com/EMDMilliporeBioscience

                2 - EM

                Twitter logo / link EM

                https://twitter.com/EMDMilliporeBio

                2 - MM

                Facebook logo / link MM

                http://www.facebook.com/MerckMilliporeBioscience

                2 - MM

                Twitter logo / link MM

                https://twitter.com/Merck4Bio

                 

                 

                As you can see, the URLs are not static and may change from document to document. Therefore, the approach initially proposed, based on my first posting, won't work.

                 

                Thanks for reading.

                • 5. Re: Automating URLs of catalogue numbers in InDesign CS4
                  MatthewMariani Level 1

                  Hi Paul,

                   

                  The effort needed to develop an automated solution is probably worthwhile in this case. The most effective way of accomplishing the desired outcome depends on many factors, such as the current work process involved in creating the InDesign layouts and how the information in the Excel workbooks is compiled. This is probably not something you can reasonably expect someone to do for you for free, but it would not be an especially costly endeavor, either.

                  • 6. Re: Automating URLs of catalogue numbers in InDesign CS4
                    Paul Hurd Level 1

                    I agree. Thanks for the insight.

                    • 7. Re: Automating URLs of catalogue numbers in InDesign CS4
                      Paul Hurd Level 1

                      Matthew, is this something that you'd be willing to take on?

                      • 8. Re: Automating URLs of catalogue numbers in InDesign CS4
                        MatthewMariani Level 1

                        Sure. You can contact me privately at marianimatthew@gmail.com to arrange a time to discuss.

                        • 9. Re: Automating URLs of catalogue numbers in InDesign CS4
                          flexipop

                          Haakenlid - Thankyou for this script.

                           

                          I am totally new to Indesign scripting, but this script nearly does exactly what I require.

                           

                          It converts this :-

                           

                          1. 2345674 > Product info description here and Price

                           

                          into this

                           

                          1. 2345674 > Product info description here and Price

                           

                          With the url generated - www.mysite.com/2345674

                           

                          What I need to do is covert this :-

                           

                          1. 2345674 > Product info description here and Price

                           

                          to this

                           

                          1. 2345674 > Product info description here and Price

                           

                          Note the whole thing becomes a link ( The whole sentence has a paragraph style applied to it, with the nested Charcter style applied to the reference number only. )

                           

                          The url generated will still be www.mysite.com/2345674

                           

                          Additionally there are multiple paragraph styles to target ( to accommodate different amount of Tab variations)  but are all named with a similar naming protocol.

                          The nested style within is always the same name.

                           

                          ie: Paragraph style names similar to this  are "pricing body - 2 tabs", "pricing body - 4 tabs", "pricing body - 6 tabs" or similar.

                           

                          They are all collected in a style group folder ( Pricing strips ), again not sure if this can be targeted with scripting.

                           

                          I realise that I could just alter the script and run it several times ( to target the all paragraph styles ) - but it would be nice to do it all in one go.

                           

                          Going further, I'd actually like to create all the links on a one NEW Layer ( called "links" or something ) - I have no idea if this is possible with scripting.

                           

                          Can any one help ? Point me in the right direction ?

                           

                          Much appreciated

                          • 10. Re: Automating URLs of catalogue numbers in InDesign CS4
                            MatthewMariani Level 1

                            Would this work?

                            Note: this variation would remove any pre-existing hyperlinks that any of the pricing body - styled paragraphs might have.

                            Also, you might need to adjust the script to make sure the exact name fragment of the paragraph style is being used: .search(/^pricing/) assumes that every one of the target paragraph style names begins with that character sequence "pricing" and it is case sensitive.

                             

                            var myDoc = app.activeDocument;
                            var myLinkStyle = myDoc.characterStyles.itemByName("link"); // the Character style of the links
                            var myURL = "http://www.mycompany.com/catalogue/"; // url of your company
                            var i, myLinks, myLink, mySource, myDestination;
                            
                            for (i = myDoc.hyperlinkTextSources.length-1; i >= 0; i--){
                                mySource =  myDoc.hyperlinkTextSources[i];
                                if (mySource.sourceText.appliedCharacterStyle == myLinkStyle){
                                    mySource.remove(); // removes existing hyperlinks to avoid "double bookings"
                                }
                                else if ( mySource.sourceText.paragraphs[0].appliedParagraphStyle.name.search(/^pricing/) == 0 ) {
                                    mySource.remove(); // removes existing hyperlinks to avoid "double bookings"
                                 }
                            }
                            
                            app.findGrepPreferences = null;
                            app.findGrepPreferences.appliedCharacterStyle = myLinkStyle;
                            myLinks = app.findGrep();
                            
                            for (i = 0; i < myLinks.length; i++){
                               myLink = myLinks[i];
                               mySource = myDoc.hyperlinkTextSources.add(myLink.paragraphs[0]);
                               myDestination = myDoc.hyperlinkURLDestinations.add(myURL + myLink.contents);
                               myDoc.hyperlinks.add(mySource, myDestination);
                            }
                            
                            
                            • 11. Re: Automating URLs of catalogue numbers in InDesign CS4
                              flexipop Level 1

                              Hello :- When I posted this question last October, I had just started working on a large mail order catalogue and the above script worked perfectly for my test document.

                               

                              The project is now finished, but when I tried to use the script, I am having problems.

                               

                              Two things have happened since I posted.

                               

                              1) I am trying to use the script in CS6 ( I tested the script in CS4 and it worked perfectly )

                              2) I have changed the formatting of the pricing strips slightly. Where before, there was only one nested style, there are now 4 nested styles for each pricing strip.

                               

                              Old pricing strip

                              2345674( nested style to target ) > Product info description here and Price

                               

                              New pricing strip

                              2345674( nested style to target ) > Product info description ( nested style 2 ) £Price ( nested style 3 ) £Price ( nested style 4 )

                               

                              In CS6, the script won't produce any hyperlinks if there are more than 1 nested style. As soon as I remove the other nested styles, the script works again.

                               

                              Incidentally, I did the same testing in CS4 and it still works fine ( even with multiple nested styles ).

                               

                              It is always the first nested style that I need to target ( ie take the information from ). Is there an array of nested styles ? Someway of referencing the first nested style like MyNestedStyle[0] or similar, rather than targetting it by name ( I am assuming that this is what the problem is ).

                               

                              Any ideas or help would be most welcome - many thanks

                              • 12. Re: Automating URLs of catalogue numbers in InDesign CS4
                                MatthewMariani Level 1

                                Hi flexipop,

                                 

                                I think I would just use grep to isolate the catalog number and ignore the nested styles.

                                 

                                Are catalog numbers ALWAYS composed of integers ONLY?

                                 

                                Is the greater-than symbol ALWAYS a delimiter between the catalog number and the product info description?

                                 

                                Do you want the entire paragraph to act as a hyperlink source or only the product info description?

                                If the latter, does this symbol £ ALWAYS separate the product info description from the price?

                                 

                                Matthew

                                • 13. Re: Automating URLs of catalogue numbers in InDesign CS4
                                  flexipop Level 1

                                  Hi Mathew :- Thanks for the response.

                                   

                                  I think I confused things with my formatting in the previous post. A typical pricing block actually looks like this :-

                                   

                                   

                                  123456 Product description £23.44 £33.44

                                  123456 Description here £13.44 £20.44

                                  124456 Product description £23.44 £33.44

                                  12345 Product description £23.44 £33.44

                                  223456 Description here £23.44 £33.44

                                  895637 Product description £23.44 £33.44

                                  543556 Description £23.44 £33.44

                                  654536 Product description £23.44 £33.44

                                   

                                  98% of the codes are 6 digits, there are a few odd ones that are 5 and 4 digits.

                                  They are always integers.

                                  There are no greater than symbols at all ( Sorry I was trying to illustrate the nested styles in the previous post )

                                  I want the ENTIRE paragraph to act as a hyperlink ( as in the original post ).

                                  There is always at least one POUND ( £) symbol.

                                  Most of the price strips have TWO prices ( as above ) - indicating Price before VAT tax and Price with VAT ( Tax)

                                  However some of the products have only one price ( see ex. below ) where the product has no added VAT.

                                   

                                  654536 Product description with no added tax  £33.44

                                   


                                  I think you are right though, it is the nested styles that seem to be causing the original script ( which was perfect ) not to run in CS6.

                                   

                                  One thing I did try, to combat this, was to convert all the instances of the first nested style to XML TAGS ( by mapping styles to tags - this had the affect of removing the nested element of the char style and applying it locally) , then ran the script. This actually had a certain amount of success ( it added links to over 1000 price strips ) but caused an error relating to the tags themselves ( which I didn't understand ).

                                   

                                  Is there a script which would go through the document and remove all nested styles and turn them into individually applied local character styles ? I could then run the original script.

                                   

                                  Thanks for you continued help with this. Much appreciatd.

                                  • 14. Re: Automating URLs of catalogue numbers in InDesign CS4
                                    MatthewMariani Level 1

                                    Hi flexipop,

                                     

                                    Would the variation below work for you? The nested styles aren't needed for this script. It does assume that every four to six digit string of integers at the start of any paragraph is a catalogue number.

                                     

                                    #target "InDesign"
                                    var myDoc = app.activeDocument;
                                    var myURL = "http://www.mycompany.com/catalogue/"; // url of your company
                                    var i, myLinks, myLink, mySource, myDestination;
                                    
                                    for (i = myDoc.hyperlinkTextSources.length-1; i >= 0; i--){
                                        mySource =  myDoc.hyperlinkTextSources[i];
                                        if ( mySource.sourceText.paragraphs[0].appliedParagraphStyle.name.search(/^pricing/) == 0 ) {
                                            mySource.remove(); // removes existing hyperlinks to avoid "double bookings"
                                         }
                                    }
                                    
                                    app.findGrepPreferences = null;
                                    app.findGrepPreferences.findWhat = "^\\d{4,6}";
                                    myLinks = myDoc.findGrep();
                                    app.findGrepPreferences = null;
                                    
                                    
                                    for (i = 0; i < myLinks.length; i++){
                                       myLink = myLinks[i];
                                       mySource = myDoc.hyperlinkTextSources.add(myLink.paragraphs[0]);
                                       myDestination = myDoc.hyperlinkURLDestinations.add(myURL + myLink.contents,  {hidden:true});
                                       myDoc.hyperlinks.add(mySource, myDestination);
                                    }
                                    
                                    
                                    • 15. Re: Automating URLs of catalogue numbers in InDesign CS4
                                      flexipop Level 1

                                      Thanks again Matthew, that did the trick first time.

                                      • 16. Re: Automating URLs of catalogue numbers in InDesign CS4
                                        John Kriho

                                        If anyone is looking for a solution in this area, we now have a commercial product that handles this very well. Please check out www.meadowsps.com/pdfexporter for more information. As an added benefit you get full database connectivity as well.

                                         

                                        Thanks,

                                         

                                        JK