How to Automatically Apply a Late Fee Based on a Date in PDF Forms
Question details
The user needs to automatically insert a $50 late fee into a designated form field when the current date passes a predetermined cutoff date.

- Product
- Device & OS
- not provided
- Scenario
- Creating an interactive invoice or registration form that automatically enforces late payment policies without manual data entry.
- Observed behavior
- Requires a script to evaluate the system's current date against a specified deadline date and output a specific monetary value if the condition is met.
Ensure your PDF document is set up as an interactive form and contains a specific text field named exactly 'Fee' (or your preferred name) to display the calculated result.
Use a Document-Level JavaScript Calculation
Implement a custom JavaScript snippet at the document level to compare the current system date with a static cutoff date whenever the PDF is opened.
A document-level script executes automatically in the background when the user opens the PDF file. By using the util.scand function, you can convert a text-based date into a readable format for mathematical comparison against the current date.
Open your PDF form in your PDF editor. Navigate to the 'Tools' menu, select 'JavaScript', and click on 'Document JavaScripts'.
Enter a name for your script, such as 'LateFeeCalculation', and click 'Add'. The JavaScript editor window will appear with an automatically generated function block.
Delete the default function body entirely and replace it with the following code: var cutoffDate = util.scand("mm/dd/yyyy", "04/10/2020"); var now = new Date(); this.getField("Fee").value = (now.getTime() > cutoffDate.getTime()) ? "50" : "";
Click 'OK' to close the editor, then save your PDF. Reopen the PDF to verify that the 'Fee' field updates automatically based on today's date compared to the cutoff date.

Manage and Fill Interactive PDF Forms with WPS Office
WPS Office provides a highly capable PDF toolkit that allows you to seamlessly fill, read, and manage interactive PDF documents containing embedded JavaScript calculations.
- 1. Download the software: Install WPS Office Free from the official WPS website onto your device.
- 2. Open the PDF form: Launch WPS Office, click 'Open', and select your interactive PDF file.
- 3. Interact with the document: Click on any form fields to input data. Built-in calculations will automatically trigger and display the correct outputs.
- 4. Save your filled form: Click 'Save' or press Ctrl+S to store your completed document securely.

Frequently Asked Questions
Why is the late fee not appearing even though the date has passed?
This commonly occurs if the target field name in your script (e.g., 'Fee') does not perfectly match the field name in the PDF properties. It is case-sensitive. Additionally, ensure JavaScript is enabled in your PDF viewer's security preferences.
Can I format the late fee to display with a currency symbol?
Yes. Instead of changing the script, open the properties for the 'Fee' form field, go to the 'Format' tab, select 'Number', and choose your preferred currency symbol. The script's '50' will automatically format as '$50.00'.
How can I compare against a date entered by the user instead of a fixed date?
Instead of hardcoding the date string in the script, you can retrieve the date from another text field using code like: var userDateString = this.getField("DueDate").valueAsString; var cutoffDate = util.scand("mm/dd/yyyy", userDateString);
Will this script run every time someone opens the PDF?
Yes, as a document-level JavaScript, it is evaluated whenever the file is opened or initialized, relying on the operating system's current clock to determine the 'now' variable.




