4 Replies Latest reply: Aug 7, 2014 8:43 AM by jajawheels RSS

    Remove spawned template/new page

    jajawheels

      Hello,

       

      Thanks in advanced for taking the time to assist me.

       

      I have a single-paged .pdf document. On this page is a field with an action which uses javascript to spawn a template. This field has a couple of options, so based on the value of the field, the appropriate template becomes the second page of the document. Currently, each time the field is selected and the action is triggered, a new page is added to the end of the document (page 3, 4, 5, etc.). This is not the ideal situation. I created a second button called Remove Form, which I intend to use to remove the previously created page 2 so that the templates just replace each other on page 2 of the document.

       

      Now, I'm aware that the template does become a page once it is spawned and that the this.deletePages() method is available. However, how do I use such a method as an action in the button layout below?

       

      Thank you!

       

      Capture.PNG

        • 1. Re: Remove spawned template/new page
          MichaelN Community Member

          Have a look at the parameters of the spawn() method.

           

          nPage lets you specify which page the template will be created on (or after). So if you want to spawn it on to an existing page 2, the nPage parameter would be 1 (it is 0-based numbering).

           

          Also, the bOverlay parameter needs to be set to true if nPage has a specific page on which you want to spawn the template. If it is false, the new page is spawned before the specified page.

          • 2. Re: Remove spawned template/new page
            jajawheels Community Member

            Thank you Michael.

             

            I edited the a.spawn(); to a.spawn(1); - however, this only overlaid the template on top of the first template that was already there (page 2). Is it possible to remove the template that is now underneath so that the reader can see the new template without the first template in the background?

             

            -Miles

            • 3. Re: Remove spawned template/new page
              MichaelN Community Member

              If you want to delete the page 2 that is spawned from a previous template, you could try something like this:

               

              if (this.numPages > 1)       //Check to see if there already is a page 2
              {
              this.deletePages(1)        //If there is a page 2, delete it
              }

              var a = this.getTemplate("New Page");   //Enter the name of your template here
              a.spawn();

              • 4. Re: Remove spawned template/new page
                jajawheels Community Member

                Thank you Michael. This worked great.