3 Replies Latest reply on Mar 15, 2013 4:42 PM by try67

    Copy button on every page w/ Javascript

    choprils

      Hi, im creating a presentantion PDF with a few buttons that i want to repeat on every page.

       

      Im already setting their function using javascript, see:

       

      ----------------------

       

      var bt1 = this.getField("sair.Page 1");

      bt1.setAction("MouseUp", "app.fs.isFullScreen = false;");

      bt1.delay = false;

       

      var bt2 = this.getField("tela.Page 1");

      bt2.setAction("MouseUp", "app.fs.isFullScreen = true;");

      bt2.delay = false;

       

      var bt3 = this.getField("indice.Page 1");

      bt3.setAction("MouseUp", "this.pageNum = 1;");

      bt3.delay = false;

       

      app.fs.clickAdvances = false;

       

      ----------------------

       

      What i want to do is to copy this 3 buttons to every other page on the document using Javascript, instead of doing it manually.

       

      I found the code below on JavaScript™ for Acrobat® API Reference, but i could not figure out how to apply this to my case.

      Since the buttons are not created via script, only their functions.

       

      ----------------------

       

      Copy a given annotation to every page in the document.

       

      var annot = this.addAnnot({

      page: 0,

      type: "Text",

      rect: [40, 40, 140, 140]

      });

      // Make a copy of the properties of annot

      var copy_props = annot.getProps();

      // Now create a new annot with the same properties on every page

      var numpages = this.numPages;

      for (var i=0; i < numpages; i++) {

      var copy_annot = this.addAnnot(copy_props);

      // but move it to page i

      copy_annot.page=i;

       

      ----------------------

       

       

       

      Thanks in advance

        • 1. Re: Copy button on every page w/ Javascript
          George_Johnson MVP & Adobe Community Professional

          There is no similar method for copying a field programmatically. You can either use the doc.addField method to add a field to the pages and then set its properties or spawn a hidden template page that just contains the buttons as an overlay on each page.

           

          Out of curiosity, why are you including this: bt1.delay = false;

           


          1 person found this helpful
          • 2. Re: Copy button on every page w/ Javascript
            choprils Level 1

            I will give it a try! Thanks

             

            I dont know the correct use of the delay=false;

             

            Im just a graphic designer, and i have done this only by reading the examples of the API, my intention was just to make sure there was no delay in the script execution. That seemed important

            • 3. Re: Copy button on every page w/ Javascript
              try67 MVP & Adobe Community Professional

              If you want an exact copy of a button on multiple pages the easiest way to

              do it is to go to Form Edit mode, then right-click the button and select

              Duplicate. Then you enter the page range to duplicate to, and you're done.

              No scripts required.

               

              If you really want to do it with a script you'll need to use the addField

              method, as was described earlier.