9 Replies Latest reply on May 8, 2013 8:22 AM by typographics79

    Creating a custom link using the Action Wizard

    typographics79

      Hi everyone! I hope someone can help me.

       

      I would like to create an action, using the Action Wizard, to make custom links. I work with extremely large PDF documents at a major airline. I am in charge of watermarking and linking all support manuals for the airplanes. We have a custom watermark that we apply to particular pages, and also link them to updated pages on our own private server. I think the linking process could be made faster with a custom action.

       

      Currently I use this code:

       

      app.launchURL("CODE", true)

       

      The "code" is the web address of the document online. This works fine, however, I still have to click the link button, reposition the link, and edit the code for the particular page. Then I have to do that hundreds of times a week.

       

      I'd like a link action, where I can click one button and the link is perfectly drawn and placed in the exact location I require (this never changes; The link is always the same size and in the same location). I'd like this to work the same as my custom watermark action works. With my watermark action, I simply specified where the watermark went on the page, what type size, color, etc. using javascript. I'm hoping I can do the same thing with a link; Simply state what diminsions the link box needs to be and where it's located on the page.

       

      If this is possible, I'd be able to do both in one click; Apply my watermark with a link box already drawn on top of it. Then all I'd need to do is edit the link with the web address of the file I'm linking to.

       

      I hope this makes sense. Any help would be appreciated!

       

      Matthew~

        • 1. Re: Creating a custom link using the Action Wizard
          try67 MVP & Adobe Community Professional

          Have a look at the addLink method. It allows you to create a new link at

          the location you wish, and then you can use the setAction method to apply

          this script to it.

          • 2. Re: Creating a custom link using the Action Wizard
            typographics79 Level 1

            Thanks, this is helpful. Can you point me in the right direction as to where I can learn more about these methods and how I can input them into the Javascript Editor? My code writing isn't strong. I tried google, but I'm not finding the actual code I need to input.

             

            Thank you again for your quick reply. I really appreciate it.

             

            Matthew~

            • 4. Re: Creating a custom link using the Action Wizard
              typographics79 Level 1

              Okay, I'm really close to what I want. If you could help me with this one little thing, I'll be golden.

               

              My watermark is text that says "See Supplemental Information". I'm using a script that finds words and draws a link around them. That's perfect for me, except I need to search for the entire phrase "See Supplemental Information".

               

              Here is my code:

               

              /* LINKING */

              for (var p = 0; p < this.numPages; p++)

                        {

                                  var numWords = this.getPageNumWords(p);

                                  for (var i=3; i<numWords; )

                                  {

                                            var ckWord = this.getPageNthWord(p, i, true);

                                            if ( ckWord == "See Supplemental Information")

                                            {

                                                      var q = this.getPageNthWordQuads(p, i);

                                                      // Convert quads in default user space to rotated

                                                      // User space used by Links.

                                                      m = (new Matrix2D).fromRotated(this,p);

                                                      mInv = m.invert()

                                                      r = mInv.transform(q)

                                                      r=r.toString()

                                                      r = r.split(",");

                                                      l = addLink(p, [r[4], r[5], r[2], r[3]]);

                                                      l.borderColor = color.red;

                                                      l.borderWidth = 1;

                                                      l.setAction("app.launchURL('https://website.com', true)");

                                            }

                                  }

                        }

               

              The code works if I only search for one word, but when I try to search for a phrase, it doesn't do anything. Is there a way to search for an entire phrase like what I need?

               

              Thanks for all your help.

               

              Matthew~

              • 5. Re: Creating a custom link using the Action Wizard
                try67 MVP & Adobe Community Professional

                getPageNthWord() returns only a single work. You need to test the current word, the next one and the one after that, like so:

                if (this.getPageNthWord(p, i, true)=="See" && this.getPageNthWord(p, i+1, true)=="Supplemental" && this.getPageNthWord(p, i+2, true)=="Information")

                 

                Another issue is that you'll need to combine the quads of all of these words and convert them into a rect array (your current code will only place the link on top of the first word). That is a more complex task and would require an advanced function to combine the quads, and possibly also deal with cases where such a combination is not possible (for example, when the phrase is spread over two lines, or even two pages).

                • 6. Re: Creating a custom link using the Action Wizard
                  typographics79 Level 1

                  Yes. That sounds complicated.

                   

                  Maybe I can simply do a search for the word "Supplemental" and have the script draw a predefined box around the word? Is that possible? The box could be bigger to go around the other words?

                   

                  If not, I can live with this solution:

                   

                  /* LINK */

                  var linkWidth = 20, linkHeight = 210;

                  for (var i = 0; i < this.numPages; i++)

                  {

                  var lRect = [50, linkHeight, linkWidth, 627];

                  var leftLink = this.addLink(i, lRect);

                  leftLink.setAction("app.launchURL('CODE', true)");

                  leftLink.borderColor = color.transparent;

                  leftLink.borderWidth = 1;

                  }

                   

                  However, that only creates the link on the first page (var i = 0). What do I replace that piece of the code with to allow a link to be placed on the current page I'm viewing? With my watermark script, the code is (nStart: this.pageNum,) but that doesn't work here.

                   

                  Again, any help would be amazing. You've already helped me greatly.

                   

                  Matthew~

                  • 7. Re: Creating a custom link using the Action Wizard
                    typographics79 Level 1

                    This is what my watermark looks like, if this helps.

                     

                    Capture.JPG

                    • 8. Re: Creating a custom link using the Action Wizard
                      try67 MVP & Adobe Community Professional

                      You can't really use this.pageNum in an Action because each file is opened,

                      processed and then closed, so there's no room for (much) user interaction.

                      If you want to add the link to the current page the user is viewing, an

                      Action is not the way to do it.

                       

                      The code you posted seems like it should add a link to each page of the

                      document...

                      • 9. Re: Creating a custom link using the Action Wizard
                        typographics79 Level 1

                        THE FINAL SOLUTION

                         

                        I'm simply posting this in case someone comes along with the same question as I had. Below is the final code I put together that works. I'm still hopeful I can make the other code work, the one that links all the watermarks at one time, and if I can I'll come back and post that code also. Special thanks to Gilad D who was very helpful.

                         

                        /* LINK */

                        var linkWidth = 20, linkHeight = 210;

                        for (var i = this.pageNum; i < this.numPages; i++)

                        {

                        // These are the coordinates for the link:

                        var lRect = [50, linkHeight, linkWidth, 627];

                        // This defines the Link object:

                        var leftLink = this.addLink(i, lRect);

                        // This sets the link action:

                        leftLink.setAction("app.launchURL('CODE', true)");

                        // This controls the link appearance:

                        leftLink.borderColor = color.transparent;

                        leftLink.borderWidth = 1;

                        }