PDF Editing Issues

How to Auto-Fill Current Date in Blank PDF Fields

Huma Ashraf ChHuma Ashraf Ch Nov 3, 2026 868 views

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.

How to Auto-Fill the Current Date in a Blank PDF Field
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.
Before you start

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').

Solution 1Recommended

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.

1
Open Form Editing Mode

Open your PDF form in your PDF editor and enter the Form Editing or Prepare Form mode.

2
Access JavaScript Settings

Navigate to the JavaScript settings and select the option to add a 'Document JavaScript' or 'Document-level script'.

3
Insert the Date 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()); }

4
Save and Test

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.

Preserves Manual Edits: This method ensures that if a user manually changes the date and saves the file, their custom date will not be overwritten the next time the PDF is opened.
Advanced PDF Form Editing

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. 1. Open WPS Office: Launch WPS Office and open your target PDF file.
  2. 2. Access the Form Tools: Navigate to the 'Form' tab on the top ribbon to view all interactive field options.
  3. 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. 4. Save Form Changes: Click 'Save' to ensure your form field structures are preserved for future data entry.
Easily insert, edit, and manage PDF form fieldsHigh compatibility with standard PDF formats and Adobe AcrobatLightweight application for fast document loadingCross-platform support for Windows, Mac, and mobile
microsoft office alternative - wps office

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.