How to Show or Hide PDF Text After a Delay with JavaScript
Question details
The user wants to display or conceal specific text and images in a PDF document after a specified time delay using Acrobat JavaScript.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms or documents that require timed visibility of text or graphical elements.
- Observed behavior
- The user needs a script and workflow to trigger delayed visibility changes for content within a PDF file.
Ensure you have a professional PDF editing program that supports document-level JavaScript and interactive form fields. Standard web browser PDF viewers often block advanced JavaScript commands.
Using JavaScript and Hidden Form Fields to Delay Text Display
By placing your text inside a form field (or covering it with one) and applying the app.setTimeOut JavaScript method, you can control visibility based on a timer.
Standard static PDF text cannot be directly animated or timed. To achieve this effect, you must convert the text into a form field or use an opaque form field as a cover over the text.
The app.setTimeOut method executes a string of JavaScript after a specified number of milliseconds, allowing you to change the field's display property dynamically.
Open your PDF in an advanced editor. Create a text field or button over the text you want to hide, and assign it a name (e.g., 'CoverText1'). Set its initial visibility to hidden or visible under the field's Properties, depending on your goal.
Navigate to the Page Properties or the Action tab of an interactive button. Select 'Run a JavaScript' as the action trigger.
Enter the following code in the JavaScript editor: app.setTimeOut("this.getField('CoverText1').display = display.visible;", 5000); . Adjust the '5000' value to your desired delay in milliseconds (where 5000 equals 5 seconds).
Save the PDF document. Open it in a dedicated desktop PDF viewer to test the timer, as browser-based viewers usually restrict script execution.

Edit and Manage Interactive PDFs with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to easily insert text, manage form fields, and edit document content without needing expensive software.
- 1. Download and Install: Download WPS Office Free and open your PDF document in the WPS PDF editor.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access interactive text fields, checkboxes, and buttons.
- 3. Insert and Manage Fields: Click 'Text Field', draw it over your desired area, and double-click to adjust its properties, name, and default visibility.
- 4. Save the Interactive Document: Click 'Save' to preserve your interactive form properties securely in standard PDF format.

Frequently Asked Questions
Why isn't my PDF JavaScript working in Google Chrome?
Web browsers like Google Chrome, Microsoft Edge, and Safari use built-in PDF viewers that intentionally disable advanced interactive features and JavaScript for security and performance reasons. For JavaScript to function, the PDF must be opened in a dedicated desktop application.
Can I use JavaScript to hide an image instead of text in a PDF?
Yes. You can apply the same logic by setting an image as the icon of a Button form field. You can then use the app.setTimeOut method to change the display property of that button field to display.hidden or display.visible.
How is the delay time calculated in PDF JavaScript?
The delay time in the app.setTimeOut method is calculated in milliseconds. For example, a value of 1000 equals 1 second. If you want a 10-second delay, you would enter 10000 in your script parameters.
Is it possible to loop or repeat the delayed action in a PDF?
Yes, you can use the app.setInterval method instead of app.setTimeOut if you need the script to execute repeatedly at a specific interval. However, looping scripts can cause performance issues in complex PDFs and should be used cautiously.




