How to Auto-Fill Current Date in Blank PDF Fields
Question details
The user needs a PDF form to automatically populate an empty date field with the current date upon opening, without overriding previously saved dates or preventing manual edits.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Opening a PDF form that contains a date field meant to capture the initial access date or the current date when first filled out.
- Observed behavior
- The user wants the date field to auto-fill only if it is blank, maintaining the date from previous sessions on subsequent openings.
Ensure you have an advanced PDF editor that supports document-level JavaScript, and identify the exact field name of your target date field (for example, 'DateField').
Use Document-Level JavaScript to Check and Set the Date
Add a script that checks if the field is empty before assigning the current date to prevent overwriting existing data.
By using document-level JavaScript, the PDF will execute this script immediately when the file is opened. The logic checks whether the field has a null or empty value, updating it with the current date only if that condition is true.
Open your PDF form in your PDF editor and enter the Form Editing or Prepare Form mode.
Navigate to the JavaScript settings and select the option to add a 'Document JavaScript' or 'Document-level script'.
Name your script (e.g., 'AutoDate') and insert the following code: if (this.getField("DateField").value == null || this.getField("DateField").value == "") { this.getField("DateField").value = util.printd("yyyy-mm-dd", new Date()); }
Replace 'DateField' with the actual name of your date field, save the script, and exit form editing. Save the document, close it, and reopen it to test if the date populates.
Easily Manage PDF Forms with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to create interactive forms, add text fields, and manage document settings effortlessly.
- 1. Open WPS Office: Launch WPS Office and open your target PDF file.
- 2. Access the Form Tools: Navigate to the 'Form' tab on the top ribbon to view all interactive field options.
- 3. Edit the Date Field: Select the existing date field to modify its properties, or add a new 'Text Field' specifically for the date.
- 4. Save Form Changes: Click 'Save' to ensure your form field structures are preserved for future data entry.

Frequently Asked Questions
Why does my PDF date field overwrite the saved date every time I open it?
This happens if your script assigns a new date unconditionally upon opening the page. Adding an 'if' statement to check if the field value is null or empty will prevent the script from overwriting saved dates.
How do I find the exact name of my PDF form field?
Enter Form Editing mode in your PDF editor, right-click the target field, and select 'Properties'. The exact field name will be listed under the 'General' tab. Ensure this matches the name in your JavaScript code exactly, as it is case-sensitive.
Can I change the date format in the JavaScript code?
Yes. In the util.printd("yyyy-mm-dd", new Date()) function, you can change "yyyy-mm-dd" to "mm/dd/yyyy" or any other standard format to match your regional formatting preferences.




