---
title: "Remove pages from a PDF file using JavaScript | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/web/editor/page-manipulation/remove/"
md_url: "https://www.nutrient.io/guides/web/editor/page-manipulation/remove.md"
last_updated: "2026-05-23T00:08:18.171Z"
description: "Remove pages from a PDF file using JavaScript | guide for Nutrient Web SDK with detailed instructions and code examples."
---

# Remove pages from a PDF using JavaScript

You can remove pages in two ways using our page editor API.

Using `keepPages` removes all the pages from the document except for the pages specified in the `pageIndexes` array:

```js

instance.applyOperations([
  {
    type: "keepPages",
    pageIndexes: [0, 1, 2] // Remove all pages except pages 0 to 2.
  }
]);

```

Using `removePages` removes the pages specified in the `pageIndexes` array:

```js

instance.applyOperations([
  {
    type: "removePages",
    pageIndexes: [8, 9, 11] // Remove pages 8, 9, and 11.
  }
]);

```

After this operation is complete, call `exportPDF` to get a buffer containing the data for the final PDF.

If you need to apply this operation and export in one step, you can provide the same argument you provide to `applyOperations` to `exportPDFWithOperations` to get a buffer containing the data for the final PDF.

---

## Related pages

- [Adding margins to PDF pages using JavaScript](/guides/web/editor/page-manipulation/add-margins.md)
- [Crop PDFs using JavaScript](/guides/web/editor/page-manipulation/crop.md)
- [Move or copy PDF pages using JavaScript](/guides/web/editor/page-manipulation/move-or-copy.md)
- [Rotating PDF pages using JavaScript](/guides/web/editor/page-manipulation/rotate.md)

