5 Replies Latest reply on Dec 28, 2012 1:35 PM by George_Johnson

    Spawning template based on value

    IAMNathan

      Hello,

       

      I'm trying to set up a script so when a user inputs a value that value would then be calculated to spawn a certain number of pages based on that value. Is this possible?

       

      Thanks.

       

      Currently using this code:

       

      // Get a template object from an existing template

      var t = getTemplate("test");

       

      // Spawn the template on the page following this one, and rename the fields

      t.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false});

        • 1. Re: Spawning template based on value
          try67 MVP & Adobe Community Professional

          Where are you placing this code? You can use the field's validation script

          to check the value and decide whether the page should be spawned or not. Do

          you know, though, that this will not work in Reader prior to XI?

          • 2. Re: Spawning template based on value
            IAMNathan Level 1

            The code is posted to a button. So if I press the botton the template will display. What I'm trying to do is ask the question: How many vehicles are involved in the accident. The user would then input that number. After the question is answered they hit a button to generate the required files "hidden templates".

             

            I don't know if it will work in reader prior to XI? I'm currently using Acrobat 9

            • 3. Re: Spawning template based on value
              try67 MVP & Adobe Community Professional
              So what you can do is put the spawn in a loop. Something like this:

               

              var numVehicles = +this.getField("NumVehicles").value;

              for (var i=0; i<numVehicles; i++)

                   t.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false});

              I was saying it won't work with Reader prior to XI. If you're using Acrobat that's OK, but the question is what the users will use...

              • 4. Re: Spawning template based on value
                IAMNathan Level 1

                Thanks for all your assistance, one step closer to completion. Hopefully no more issues!!!!!

                • 5. Re: Spawning template based on value
                  George_Johnson MVP & Adobe Community Professional

                  Note that you can use the XObject that's returned after your initial spawn of a template in subsequent spawns to reduce the size of the resulting file, sometimes significantly. See the documentation for the oXObject parameter.

                   

                  I would also recommend adding some code the the user is not able to keep adding more pages with additional presses of the button.