PDF Editing Issues

How to Copy Form Data from the Previous PDF Page Using JavaScript

Adam DavisAdam Davis Nov 2, 2026 869 views

Question details

The user needs a script to automatically copy form field values from the immediately preceding page instead of the original template in a multipage PDF.

How to Copy Form Data from the Previous PDF Page Using JavaScript
Product
PDF Editors
Device & OS
not provided
Scenario
Filling out a multipage PDF form where pages have been duplicated, requiring new fields to inherit data dynamically from the previous page to save time.
Observed behavior
Currently, spawned pages either leave fields blank or pull from the original template, failing to capture the unique data entered on the page just before them.
Before you start

Ensure your PDF editor supports JavaScript for forms (such as Adobe Acrobat) and that you fully understand the predictable field naming conventions used when pages are spawned from your template.

Solution 1Recommended

Use Acrobat JavaScript to Extract Values Based on Page Number

Identify the template name, field name, and preceding page number to copy the value programmatically using a custom calculation script.

When pages are spawned from a template in a PDF, the newly created fields typically follow a predictable, structured naming pattern (for example, 'P1.TemplateName.FieldName').

By parsing the current page number dynamically, you can construct the exact field name of the previous page and extract its value using Acrobat JavaScript.

1
Identify Spawned Field Names

Open the Field Properties in your PDF editor to identify the exact template prefix and naming pattern applied to your duplicated form fields.

2
Access Custom Calculation Script

Right-click the target field on the newly spawned page, select 'Properties', navigate to the 'Calculate' tab, and choose 'Custom calculation script'.

3
Calculate the Previous Page Number

In the script editor, get the current page number using the property 'event.target.page' and subtract 1 to target the immediately preceding page.

4
Retrieve and Apply the Data

Construct the previous field's name string, use 'this.getField(PreviousFieldName)' to locate it, and assign its value to 'event.value' so the current field inherits the data.

Use Acrobat JavaScript to Extract Values Based on Page Number
Field Naming Rules: Ensure your template forms have properly structured names before spawning, otherwise the JavaScript cannot reliably predict the target field on the preceding page.
Advanced PDF Form Management

Easily Fill and Manage PDF Forms with WPS Office

WPS Office offers a comprehensive PDF editor that allows you to effortlessly fill out interactive forms, edit document text, and manage multipage PDFs with intuitive tools, bypassing the need for complex scripting.

  1. 1. Open PDF Document: Launch WPS Office, select the PDF module, and open your multipage form document.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all interactive fields and their properties.
  3. 3. Manage Pages: Click on the 'Page' tab to easily duplicate, extract, or insert pages visually.
  4. 4. Save and Export: Once your data is entered, click 'Save' to retain standard PDF form compatibility with all major viewers.
Easily fill, edit, and sign interactive PDF forms without writing custom codeFully compatible with standard PDF formats including Adobe Acrobat formsExtract, merge, and duplicate PDF pages in just a few clicksLightweight and available on Windows, Mac, Linux, iOS, and Android
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF JavaScript not executing on the spawned page?

JavaScript may be disabled in your PDF viewer's security preferences, or the field names referenced in your script do not exactly match the predictable pattern generated on the newly spawned page.

Can I copy form data across pages without using JavaScript?

Yes. If you want fields on different pages to mirror the exact same data continuously, you can simply give them identical field names in the Form Properties. However, if they need to be distinct but just inherit initial values, scripting is required.

How do I find the exact field name in a PDF form?

Enter form editing mode in your PDF software. Right-click the form field and select 'Properties' or 'Field Settings'. Under the General tab, you will see its exact Name, which is crucial for targeting it with JavaScript.

What happens to the form data if I delete the previous page?

If the current page's script relies on reading the previous page dynamically upon calculation, deleting that previous page will result in a null value or script error, unless the copied data was already converted to a static text value.