Skip to main content
WPDSWINGMAN
Participant
March 16, 2026
Question

Javascript button that duplicates a page, clears form fields and renames form fields making them unique?

  • March 16, 2026
  • 1 reply
  • 38 views

I have a fillable PDF with multiple pages. On one page is a table with a lot of form fields and sometimes our users need extra pages with this table on it. I have a button that duplicates the page but if there is any information on the original page it pulls that as well. Is there a way for the button to duplicate the page with blank and unique form fields as well as bring the button along with it in case more pages are needed? Current JavaScript being used is below:

var expTplt = getTemplate("800.02 Table");

expTplt.spawn(numPages,true,false);

    1 reply

    Thom Parker
    Community Expert
    Community Expert
    March 16, 2026

    Is the original page also the template? If it is, then this is the reason that values are being copied. The new page is being spawned from a page that already has filled fields, so it copies those fields. Template pages should always be reset and hidden, so the spawn is from a clean page.

    The Original, or first, table page should be either a previously spawned template page, or a separate page entirely. 

     

    Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
    WPDSWINGMAN
    Participant
    March 16, 2026

    Yes the original page is also the template. The button will work properly if no data is entered in the original, meaning the duplicated page will have unique fields. The problem is this form evolves through the life of the project that it collects data from so pages can be added later on.

    Thom Parker
    Community Expert
    Community Expert
    March 16, 2026

    So you have a couple of choices for a solution. In both, the template page must be cleared and set to hidden. 

    1.  Before hiding the template page, duplicate the template page using a regular page copy operation. The new page will not be a template, and it will act as the first page of fields. Now hide the template page.
    2. Hide the template page and use the console window to run the spawn code for creating the first page of fields. 

     

    Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often