How to Add a Self-Updating Expiration Date to Every PDF Page
Question details
The user needs to insert a dynamic date into a PDF footer that automatically updates when printed, indicating that the document expires a set number of days (e.g., 5 days) after the print date.

- Product
- Device & OS
- not provided
- Scenario
- Preparing a time-sensitive document that requires an automated expiration date to be calculated and printed at the bottom of every page at the exact time of printing.
- Observed behavior
- Standard text fields remain static and do not update upon printing. The user needs a script-driven solution to dynamically refresh the date across all pages.
Ensure you are using a desktop PDF editor that supports advanced form field properties and document-level JavaScript execution, as basic PDF viewers cannot process 'Document Will Print' trigger scripts.
Use JavaScript to Create a Dynamic Print Date
Create a hidden but printable form field and use a 'Document Will Print' JavaScript action to calculate and display the expiration date.
By utilizing document-level JavaScript actions, you can set a script to run automatically right before the document is sent to the printer. This script calculates a date 5 days into the future and populates a specific text field placed on all pages.
Open your PDF editor's Form or Prepare Form tool, and draw a new text field in the footer area. Name this field exactly 'PrintText'.
Right-click the 'PrintText' field and open its Properties. Under the General or Appearance tab, change its visibility setting to 'Hidden but printable' so it does not clutter the screen but will appear on the physical copy.
Copy the 'PrintText' field and paste it into the exact same footer location on every page where you want the expiration date to be visible.
Navigate to Tools > JavaScript > Set Document Actions (or Document Scripts). Select the 'Document Will Print' action trigger and click Edit or Add.
Input the following script: var d = new Date(); d.setDate(d.getDate()+5); this.getField("PrintText").value = "This document is valid until " + util.printd("mm/dd/yyyy", d); Then click OK and save your document.

Easily Manage PDF Forms and Scripts with WPS Office
WPS Office provides a comprehensive suite of PDF editing tools, allowing you to easily insert interactive form fields, manage multi-page headers and footers, and edit PDF documents without hassle.
- 1. Open WPS PDF: Launch WPS Office and open your target PDF document in the PDF editor.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to easily draw and insert text fields for your dynamic dates.
- 3. Save and Export: Once your fields are configured, save your PDF. WPS ensures high compatibility with all major PDF viewers.

Frequently Asked Questions
Can the dynamic date field be placed in the header instead of the footer?
Yes. You can place the text field anywhere on the document. Just ensure the field name identically matches the one referenced in your JavaScript (e.g., 'PrintText') and that it is duplicated on all desired pages.
Why does my dynamic stamp only show the date I originally created it?
If you add text to a dynamic stamp and save it statically, the JavaScript calculates the date once and saves the result as flat text. Dynamic stamps require active JavaScript evaluation at the time of placement or printing to update correctly.
Will these JavaScript actions work on mobile PDF viewers?
Most mobile PDF viewers and basic built-in web browser PDF readers do not fully support document-level JavaScript or form field calculations. The document will typically need to be opened and printed from a full-featured desktop PDF application for the script to execute.




