Other PDF Issues

How to Fix Invalid Argument Error When Deleting Spawned PDF Pages

Kushani NimanthikaKushani Nimanthika Nov 5, 2026 870 views

Question details

The user encounters a RangeError when attempting to delete a spawned PDF template page using a JavaScript button.

How to Fix Invalid Argument Error When Deleting a Spawned PDF Template Page
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the PDF in Form Editing Mode

Launch your PDF editor and enter the form editing or preparation mode to access interactive elements.

2
Access the button properties

Right-click the specific button designed to delete the page and select 'Properties' from the context menu.

3
Edit the JavaScript action

Navigate to the 'Actions' tab, select the 'Run a JavaScript' trigger, and click the 'Edit' button to modify the code.

4
Replace the page target code

Delete this.deletePages(event.target.page); and replace it with this.deletePages(this.pageNum);. Click 'OK' to save the changes.

Modify the JavaScript to Target the Current Page Number
Context Requirement: This targeted script works correctly when the button resides on the actual spawned template page you intend to delete.

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. 1. Open your PDF in WPS Office: Launch WPS Office and open your target PDF document.
  2. 2. Navigate to the Page tab: Click on the 'Page' tab located on the top navigation ribbon to access page management tools.
  3. 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. 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.
Easily insert, delete, and extract PDF pages without dealing with complex JavaScript code.Fully compatible with standard PDF formats and interactive elements from Adobe Acrobat.Lightweight and intuitive interface designed for fast and seamless document management.
microsoft office alternative - wps office

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.