How to Fix Invalid Argument Error When Deleting Spawned PDF Pages
Question details
The user encounters a RangeError when attempting to delete a spawned PDF template page using a JavaScript button.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Triggering a JavaScript command via a button to delete a page spawned from a PDF template.
- Observed behavior
- The code this.deletePages(event.target.page) fails and returns a RangeError: Invalid argument value instead of deleting the spawned page.
Ensure you are opening the file in a professional PDF editor, as basic PDF readers do not support executing scripts that delete or modify pages.
Modify the JavaScript to Target the Current Page Number
Replace the event target reference with the explicit current page number property to successfully pass the correct page index.
The error 'RangeError: Invalid argument value' typically occurs when the parameter passed to the deletePages method is undefined or invalid in the current execution context. Changing the reference ensures the function explicitly receives an integer representing the exact page index where the button is located.
Launch your PDF editor and enter the form editing or preparation mode to access interactive elements.
Right-click the specific button designed to delete the page and select 'Properties' from the context menu.
Navigate to the 'Actions' tab, select the 'Run a JavaScript' trigger, and click the 'Edit' button to modify the code.
Delete this.deletePages(event.target.page); and replace it with this.deletePages(this.pageNum);. Click 'OK' to save the changes.

Verify You Are Using a Compatible PDF Editor
Ensure you are using software capable of executing document-level structural modifications via JavaScript.
Easily Manage and Delete PDF Pages with WPS Office
If JavaScript errors persist or you prefer a straightforward, non-coding approach, WPS Office provides a powerful PDF editor that allows you to easily add, delete, and manage PDF pages directly from the user interface.
- 1. Open your PDF in WPS Office: Launch WPS Office and open your target PDF document.
- 2. Navigate to the Page tab: Click on the 'Page' tab located on the top navigation ribbon to access page management tools.
- 3. Select pages to delete: Click on the specific page thumbnail, or hold down the 'Ctrl' key to select multiple spawned pages you wish to remove.
- 4. Delete the pages: Click the 'Delete' button in the toolbar, or right-click the selected pages and choose 'Delete Pages' to remove them instantly.

Frequently Asked Questions
Why does a basic PDF reader block JavaScript page deletion?
Standard PDF readers restrict operations that permanently modify the document structure, such as deleting or inserting pages, for security and licensing reasons. A professional PDF editor is required to execute these actions.
What does a RangeError mean in PDF JavaScript?
A RangeError indicates that a value passed to a function is not within the allowed limits. In the context of deletePages, it usually means the page number parameter is undefined, null, or out of bounds.
Can I delete a non-spawned page using this JavaScript code?
Yes, but it requires appropriate document permissions and must be executed in a full PDF editor. However, if the script specifically checks for spawned template properties, it may bypass standard pages intentionally.




