Other PDF Issues

How to Prevent a PDF Timestamp from Changing When Reopened

John WilsonJohn Wilson Nov 5, 2026 871 views

Question details

The user needs to generate a unique date/time stamp in a PDF field via JavaScript, but wants to prevent the timestamp from updating automatically every time the file is opened.

How to Prevent a PDF Timestamp from Changing When Reopened
Product
PDF
Device & OS
not provided
Scenario
Generating a unique project-number or timestamp in a PDF form upon document creation or initial save.
Observed behavior
The timestamp script re-executes every time the PDF is opened, overriding the previously saved date and time value.
Before you start

Ensure you have access to a PDF editor that supports JavaScript form formatting, and locate the exact name of the text field you are using to store the timestamp.

Solution 1Recommended

Add a Conditional Check to the JavaScript Code

Wrap your timestamp generation script in an 'if' statement to ensure it only runs when the field is currently empty.

When a PDF executes a JavaScript code on open or print, it runs blindly unless instructed otherwise. By checking if the field is empty first, the script will only insert the current date and time the very first time it is triggered. Afterwards, since the field contains a value, the script skips the generation, locking the timestamp.

1
Open Field Properties

Enter the form editing mode in your PDF editor, right-click the text field you want to use for the timestamp (e.g., 'UniqueNumber'), and select 'Properties'.

2
Edit JavaScript

Navigate to the 'Calculate' or 'Action' tab depending on your trigger method, select 'Custom calculation script', and click 'Edit'.

3
Insert Conditional Code

Enter the following script: if (this.getField('UniqueNumber').valueAsString == '') { this.getField('UniqueNumber').value = util.printd('yymmddHHMM', new Date()); }

4
Save and Test

Click 'OK' to save the script. Save the PDF document, close it, and reopen it to verify that the timestamp remains unchanged.

Add a Conditional Check to the JavaScript Code
Field Name Matching: Ensure that 'UniqueNumber' exactly matches the name of your form field. JavaScript is case-sensitive.
Manage PDFs Easily with WPS Office

Edit and Fill PDF Forms with WPS PDF

WPS Office provides a comprehensive PDF toolset, allowing you to easily read, fill, edit, and sign PDF forms. If you're dealing with complex form fields and need a lightweight, fast, and highly compatible alternative, try WPS PDF.

  1. 1. Download and Install: Download WPS Office for free from the official website and install it on your device.
  2. 2. Open Your PDF: Launch WPS Office and open your PDF document with the built-in PDF reader.
  3. 3. Fill and Save: Easily interact with form fields, fill in required data, and save your document securely without unwanted alterations.
Fully compatible with standard PDF forms, formatting, and annotations.Lightweight and fast, opening large PDFs in seconds without lag.Cross-platform support for seamless document management on Windows, Mac, iOS, and Android.User-friendly interface requiring no steep learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my PDF timestamp update every time I print it?

If your JavaScript is set to trigger on a 'Will Print' action without a conditional check, the script will fetch the current date and time during every print job. Applying the empty-field condition prevents this recalculation.

Can I use this script for other date formats?

Yes, the util.printd function allows various date formats. For example, changing 'yymmddHHMM' to 'mm/dd/yyyy' will output the date in a standard US date format.

Will this JavaScript work on all PDF readers?

Most desktop PDF editors support basic Acrobat JavaScript. However, some simplified mobile PDF viewers or web browser extensions may not execute JavaScript at all, which means the field might remain blank in those specific environments.