Skip navigation
Currently Being Moderated

Spawn page, PDF template in Adobe X

Apr 13, 2011 10:28 AM

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: s


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'});




} // end CopyPage function 


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

  • Currently Being Moderated
    Apr 13, 2011 10:40 AM   in reply to adamss14

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

    error message in the console?

    Mark as:
  • George Johnson
    11,651 posts
    Aug 11, 2002
    Currently Being Moderated
    Apr 13, 2011 12:07 PM   in reply to adamss14

    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});
    Mark as:
  • George Johnson
    11,651 posts
    Aug 11, 2002
    Currently Being Moderated
    Apr 13, 2011 12:20 PM   in reply to adamss14

    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.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points