9 Replies Latest reply: May 5, 2011 7:03 AM by adamss14 RSS

    Spawn page, PDF template in Adobe X

    adamss14 Community Member

      Hi all, I am working on a PDF form where the user needs to be able to add more pages if they still have info to enter.  After researching this a bit, it seems the best way to go is to define the page as a PDF template, then copy that template to a new page when the user presses a button (using javascript). I am not a programmer at all, but I found this forum post: http://acrobatusers.com/forum/javascript/duplicate-current-page-5-times

       

      That gave me some code to work with, but the code doesn't work for me, even with the corrections and taking out the comments.  Any advice on how I can do this?? Thanks to anyone who responds.  Here is the code I am currently working with:

       

       

      function CopyPage(nPageNum, nTimes) {

       

       

       

         // create template from pagevar

       

         t = this.createTemplate({cName:"myTemplate", nPage: nPageNum });

       

        

       

         // hide

       

         templatet.hidden = true;

        

         // spawn nTimes pages from templatevar

         t = this.templates;

       

      var T = t[0];

        

         // get first templage

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

            T.spawn({nPage: this.numPages, bRename: false, bOverlay: false });

         }

        

         // remove the template

         this.removeTemplate({cName: 'myTemplate'});

        

         return;

       

      } // end CopyPage function 

       

      // code to call CopyPage functionCopyPage(5, 1);

        • 1. Re: Spawn page, PDF template in Adobe X
          try67 ACP/MVPs

          Where are yo running this code from, and what happens exactly? Are there any

          error message in the console?

          • 2. Re: Spawn page, PDF template in Adobe X
            adamss14 Community Member

            Hi, thanks for responding.

             

            In add/edit fields, I add a button.  In the properties of said button, under the Actions Tab, I select "Mouse Up" as the Trigger, "Run a JavaScript" as the Action, then I click edit and paste the code into the box, OK, close.  The code in my original post is not giving me any errors at all, but it's just not doing anything when I press my button.  Like, nothing executes.  As I said, I'm not a programmer and have absolutely no experience in Javascript.

            • 3. Re: Spawn page, PDF template in Adobe X
              George_Johnson ACP/MVPs

              You cannot use the createTemplate method in a script that's attached to a button. You would have to create a folder level script, or better yet, make the page a template at design time so you don't need to do so at run time. If you know in advance that you want to possible create a new page, this is what you should do.

               

              Also, when spawning a new page with fields, you should set the bRename parameter to true. Otherwise, the values of the fields on the different pages will be the same, which is probably not what you want.

               

              Let's say that you made the page on which your button is a template, and gave it the name "myTemplate". A Mouse Up script that would add a single duplicate page after it would be:

               

              // Get a template object from an existing template
              var t = getTemplate("myTemplate");
              
              // Spawn the template on the page following this one, and rename the fields
              t.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false});
              
              • 4. Re: Spawn page, PDF template in Adobe X
                adamss14 Community Member

                Thanks!! I'd like to make sure I understand what you're saying.  I can't create the current page as a template using the script attached to the button; I must do that beforehand.  Then the button merely duplicates the pre-existing template?

                 

                But how do I define the page as a template?

                 

                I am a biology person, so I apologize for not being familiar with these steps.

                • 5. Re: Spawn page, PDF template in Adobe X
                  George_Johnson ACP/MVPs

                  To make a page a tempate in Acrobat 10, open the document to the page you want to make a template and select: Tools > Document Processing > Page Template", and give it the name you want to use.

                   

                  If this needs to work with Reader, you should be aware that it cannot, unless you are able to give the document the corresponding usage right, which requires Adobe's LiveCycle Reader Extensions server-based product. Similar functionality is possible if you create a dynamic XFA form using LiveCycle Designer, which comes with Acrobat Pro, but creates an entirely different type of form. The advantage is it will work with Reader.

                  • 6. Re: Spawn page, PDF template in Adobe X
                    adamss14 Community Member

                    Thanks, I looked everywhere for that yesterday, and could not find a proper help manual for Adobe X.  (I found one today on one of your other posts, so thanks for that too).

                     

                    I thought I'd be ok if I saved it as a reader extended PDF. Thanks for the heads up about that.  I'll see what I can do.  Thanks so much for your help!

                    • 7. Re: Spawn page, PDF template in Adobe X
                      adamss14 Community Member

                      Hi, just wanted to let you know that this code worked.  Thank you so much for solving my problem.

                      • 8. Re: Spawn page, PDF template in Adobe X
                        adamss14 Community Member

                        Hi, I have a follow-up to this question.  When the user fills out the form fields on the page, then they click the "Duplicate Page" button, the new page contains the text they entered on the original page.  Is there a way for the fields to be blank when duplicated?

                         

                        Many thanks.

                        • 9. Re: Spawn page, PDF template in Adobe X
                          adamss14 Community Member

                          Sorry- I decided to begin a new thread.