PDF Editing Issues

How to Delete a PDF Page When a Button Is Clicked Using JavaScript

Olivia MillerOlivia Miller Oct 28, 2026 869 views

Question details

The user needs to know how to automatically remove a specific page in a PDF document by triggering a JavaScript action when a form button is clicked.

How to Delete a PDF Page Using JavaScript on Button Click
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Setting up interactive PDF forms where page removal is triggered by user interactions, such as button clicks, often based on specific form values.
Observed behavior
The user is looking for the correct JavaScript method and implementation steps to achieve programmatic page deletion within a PDF.
Before you start

Ensure you are using a premium PDF editor like Adobe Acrobat Pro or Standard, as free viewer applications do not support page deletion via JavaScript. Always save a backup copy of your original PDF document before running page-altering scripts.

Solution 1Recommended

Use the deletePages Method in Adobe Acrobat

Attach a JavaScript action to the Mouse Up event of your form button to trigger the built-in deletePages method.

Adobe Acrobat allows you to attach JavaScript actions to interactive form fields. The `this.deletePages()` method removes one or more pages from the document and requires an object specifying the starting and ending indices.

Keep in mind that page indexes in Acrobat JavaScript are zero-based. This means that page 1 is index 0, page 2 is index 1, and page 3 uses index 2.

1
Open Form Preparation Mode

Open your PDF document in Adobe Acrobat, navigate to the 'Tools' menu, and select 'Prepare Form'.

2
Access Button Properties

Right-click the target form button that you want to act as the trigger, and choose 'Properties' from the context menu.

3
Configure the JavaScript Action

Go to the 'Actions' tab. Select 'Mouse Up' as the trigger, choose 'Run a JavaScript' from the 'Select Action' dropdown menu, and click the 'Add' button.

4
Enter the JavaScript Code

In the JavaScript Editor window, input your deletion code. For example, to delete the third page, type: `this.deletePages({ nStart: 2, nEnd: 2 });`. Click 'OK' and close the properties window.

Use the deletePages Method in Adobe Acrobat
Compatibility Note: This method relies on document-level security privileges available only in Adobe Acrobat Pro or Standard. It will not execute in Adobe Acrobat Reader.
Easy PDF Page Management

Easily Delete and Organize PDF Pages with WPS Office

If you don't want to deal with complex JavaScript coding just to remove pages, WPS Office offers a highly intuitive, visual interface to manage, extract, and delete PDF pages without writing any code.

  1. 1. Open your PDF Document: Launch WPS Office and open the target PDF file you want to edit.
  2. 2. Navigate to the Page Tab: Click on the 'Page' tab located in the top ribbon menu to view all pages in your document as thumbnails.
  3. 3. Select the Pages to Delete: Click on the thumbnail of the page you wish to remove. You can hold down the Ctrl key to select multiple pages at once.
  4. 4. Delete and Save: Click the 'Delete' icon in the top toolbar or press the Delete key on your keyboard, then save your updated document.
Visually select and delete PDF pages instantly without writing JavaScript.Highly compatible with Adobe Acrobat PDF formats and file structures.Lightweight software that loads large PDF files smoothly and quickly.Includes comprehensive PDF editing, merging, splitting, and annotation tools.
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my JavaScript page deletion script working in Adobe Acrobat Reader?

The `deletePages` method requires elevated privileges to modify the document structure, which are only available in paid editing versions like Adobe Acrobat Standard or Pro. Adobe Reader is essentially a viewer and silently ignores commands that attempt to alter the page structure.

How do I delete multiple consecutive pages using Acrobat JavaScript?

You can adjust the `nStart` and `nEnd` parameters in the `deletePages` method. For example, to delete pages 4, 5, and 6 (which correspond to indexes 3, 4, and 5), use the code: `this.deletePages({ nStart: 3, nEnd: 5 });`.

Can I recover a page that was deleted by a JavaScript action?

If you have not yet saved the document, you can undo the action using Ctrl+Z (or Cmd+Z on Mac), or simply close the file without saving to revert to the original state. Once the file is saved, the deletion is permanent.

Is it possible to delete a page based on a dropdown menu selection instead of a button?

Yes. You can attach a JavaScript action to the dropdown field's 'On Blur' or 'Mouse Up' event. Your script can read the selected value using `event.value` and use an `if` statement to trigger `this.deletePages()` only when specific conditions are met.