How to Show Spawn and Delete Buttons Only on the Last PDF Page
Question details
Configure a PDF form so that specific interactive buttons, such as Spawn and Delete, are hidden on all pages except the final page.

- Product
- Device & OS
- not provided
- Scenario
- Creating or modifying an interactive PDF form with JavaScript-controlled buttons that should only appear at the end of the document.
- Observed behavior
- The Delete button currently appears on pages where it should be hidden, requiring a script to restrict its display dynamically based on the current page number.
Ensure your PDF editor supports JavaScript execution and advanced form field editing before modifying button visibility settings.
Use Page-Based JavaScript to Control Button Visibility
Apply a custom JavaScript script to the PDF document to automatically hide the buttons on all pages and reveal them only on the final page.
By using a page-level script, you can dynamically evaluate the current page number against the total number of pages in the document. This ensures that even if pages are spawned or removed, the buttons will consistently only appear on the final page.
Open your interactive PDF in your PDF editor and enter the 'Form' or 'Prepare Form' mode to view all interactive fields.
Right-click the Spawn or Delete button you want to modify and select 'Properties' from the context menu.
Navigate to the 'Actions' tab, choose 'Page-level scripts' or 'Run a JavaScript' as the trigger action, and click 'Add'.
Enter a script that checks if the current page is the last page (e.g., comparing pageNum to numPages - 1). Set the button's display property to 'display.visible' if true, and 'display.hidden' if false.
Save the changes, exit form editing mode, and scroll through the document to verify the buttons only appear on the final page.

Manage Interactive PDF Forms Easily with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to manage form fields, edit text, and handle interactive documents with ease.
- 1. Open Your Document: Launch WPS Office and open your PDF document containing the interactive forms.
- 2. Access the Form Tab: Navigate to the 'Form' tab on the top ribbon to access the interactive field tools.
- 3. Modify Field Properties: Select the specific button or field you want to adjust and double-click to open its properties menu.
- 4. Save Your Form: Once your fields are configured, simply click the 'Save' icon to apply your changes directly to the PDF.

Frequently Asked Questions
Why are my PDF form JavaScript buttons not working in browsers?
Most web browsers' built-in PDF viewers (like Chrome or Edge) have limited or no support for PDF JavaScript. It is strongly recommended to open interactive forms in dedicated desktop software to ensure scripts execute properly.
What is the JavaScript property used to hide a button in a PDF?
You can hide a form field by setting its display property to hidden, typically using the code: getField('buttonName').display = display.hidden;.
Can I apply this visibility logic to other form fields like text boxes?
Yes, the same JavaScript logic used for buttons can be applied to text boxes, dropdowns, or any other interactive form field by referencing the field's specific name in your script.




