PDF Editing Issues

How to Automatically Increase a Number in a PDF Form

Amos GikundaAmos Gikunda Oct 28, 2026 869 views

Question details

The user wants to automatically generate or increment a sequential protocol number in a PDF form when it is opened, completed, or printed based on specific conditions.

How to Automatically Increase a Number in a PDF Form
Product
PDF
Device & OS
not provided
Scenario
Creating a dynamic PDF protocol form that automatically tracks and increments protocol numbers.
Observed behavior
Currently, the form fields require manual entry of the protocol number, but the goal is to use conditional logic or JavaScript to automate this increment based on user input.
Before you start

Ensure you have a PDF editor that supports JavaScript calculations for form fields, and identify the exact field names (e.g., 'fill_8') you plan to reference in your script.

Solution 1Recommended

Use JavaScript to Calculate and Increase Field Values

Apply a custom calculation script to the target text field to automatically update its value based on another field's input.

By configuring a custom calculation script within the properties of a specific PDF form field, you can set up conditional logic. For example, the script can check if a user has entered data into 'fill_8' and then automatically update 'fill_20' with a higher number.

1
Open form editing mode

Open your PDF document in a compatible PDF editor, switch to the Form editing mode, and locate the field where you want the protocol number to appear.

2
Access field properties

Right-click the target field (e.g., the protocol number field) and select 'Properties' from the context menu.

3
Set up a custom calculation

Navigate to the 'Calculate' tab in the Properties dialog box, select 'Custom calculation script', and click the 'Edit' button.

4
Input the JavaScript code

Enter your conditional JavaScript logic. For example: var C = this.getField("fill_8").value; event.value = C > 1 ? 20 : 12;

5
Save and test the form

Click 'OK' to save your script, close the Properties dialog, and test the form by entering a value greater than 1 into 'fill_8' to see if the target field updates automatically.

Use JavaScript to Calculate and Increase Field Values
Sequential Tracking Limitations: PDF form fields alone cannot track cross-document revisions persistently. True sequential numbering across multiple users or sessions usually requires a database or external storage connection, as JavaScript variables reset when the document is closed unless saved directly into the document's static text.
Powerful PDF Form Editor

Create and Edit Advanced PDF Forms with WPS Office

WPS Office provides comprehensive PDF editing tools, allowing you to easily create interactive forms, add text fields, configure field properties, and manage document workflows efficiently without needing complex software.

  1. 1. Download and open WPS Office: Launch WPS Office on your device and click on the 'PDF' tab from the main interface.
  2. 2. Open your PDF document: Open the PDF file you wish to edit and navigate to the 'Form' tab in the top ribbon.
  3. 3. Insert form fields: Use the available form tools to add text fields, checkboxes, dropdowns, or buttons to your document layout.
  4. 4. Configure field properties: Right-click any newly added field to access its 'Properties', where you can set up formatting, appearance, and basic input rules.
Easily add and configure interactive PDF form fieldsHigh compatibility with standard PDF formats and Adobe AcrobatLightweight application with a user-friendly interfaceFree basic features for everyday PDF tasks and document management
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my JavaScript calculation working in the PDF?

Ensure that the field names used in your script match exactly with the names in your form, including case sensitivity. Additionally, check that JavaScript is enabled in your PDF reader's preferences and that there are no syntax errors in your code.

Can a PDF automatically remember the last printed number?

By default, a standard PDF cannot permanently remember values between different user sessions once it is closed unless the document itself is saved after the number changes. To maintain a strict running sequence across multiple print jobs by different users, you typically need to connect the form to an external database.

How do I trigger a script right before printing the PDF?

You can use document-level JavaScript and attach a script to the 'Will Print' event. Go to your PDF editor's Document Actions or JavaScript settings, select 'Document Will Print', and enter the code needed to update the specific field right before the print dialogue opens.