---
title: "Edit page label in a PDF using JavaScript | Nutrient"
canonical_url: "https://www.nutrient.io/guides/web/editor/page-label/"
md_url: "https://www.nutrient.io/guides/web/editor/page-label.md"
last_updated: "2026-06-08T17:11:05.597Z"
description: "Edit page label in a PDF using JavaScript | guide for Nutrient Web SDK with detailed instructions and code examples."
---

# Edit page labels in a PDF

This guide explains how to edit PDF page labels in Nutrient Web SDK by applying page label operations in JavaScript.

For a cross-product overview of how PDF page labels work and how each Nutrient product handles them, refer to the [PDF page labels](https://www.nutrient.io/guides/pdf-page-labels.md) guide.

With `setPageLabel`, you can change the label of any page:

```js

instance.applyOperations([
  {
    type: "setPageLabel",
    pageIndexes: [0],
    pageLabel: "New page label"
  }
]);

```

`pageLabel` is optional, and if it’s not provided, the current page label will be cleared. The operation will fail if more than one page number is provided in the `pageIndexes` array.

#### Multiple operations

Operations can be chained in a single call to [`instance.applyOperations()`](https://www.nutrient.io/api/web/NutrientViewer.Instance.html#applyOperations) or [`instance.exportPDFWithOperations()`](https://www.nutrient.io/api/web/NutrientViewer.Instance.html#exportPDFWithOperations). When performing multiple operations, always keep in mind that the page indices in each operation must reference the corresponding page indices that result from performing the previous operation.

To better understand the implications of this behavior, below is a failing example. Assume the current document has six pages, which are indexed from `0` to `5`:

```js

instance.applyOperations([
  // First, remove the last two pages from the document.
  {
    type: "removePages",
    pageIndexes: [4, 5] // Remove pages 4 and 5.
  },
  // The resulting document would have four pages, indexed from `0` to `3`.
  // The next operation will throw an error, as there's no longer a page with index 5.
  {
    type: "rotatePages",
    pageIndexes: [5], // Rotate page 5.
    rotateBy: 90 // Rotate page 90 degrees clockwise.
  }
]);

```

On the other hand, this next example would succeed in spite of operating on a page that doesn’t exist in the original document (assume you have a six-page document again):

```js

instance.applyOperations([
  // First, add a page at the beginning of the document.
  {
    type: "addPage",
    beforePageIndex: 0, // Add new page after page 1.
    backgroundColor: new NutrientViewer.Color({ r: 255, g: 255, b: 255 }), // Set white as the new page background color.
    pageWidth: 750,
    pageHeight: 1000,
    rotateBy: 0 // No rotation.
    // Insets are optional.
  },
  // The resulting document would have 7 pages now, indexed from `0` to `6`.
  // The next operation will succeed, as page 6 now exists.
  {
    type: "rotatePages",
    pageIndexes: [6], // Rotate page 6.
    rotateBy: 90 // Rotate page 90 degrees clockwise.
  }
]);

```

## Exporting a PDF

After this operation is complete, you can call [`instance#exportPDF`](https://www.nutrient.io/api/web/NutrientViewer.Instance.html#exportPDF) to get an `ArrayBuffer` containing the data for the final PDF.

If you need to apply this operation and export the resulting document in one step, you can provide the same argument passed to [`instance#applyOperations`](https://www.nutrient.io/api/web/NutrientViewer.Instance.html#applyOperations) to [`instance#exportPDFWithOperations`](https://www.nutrient.io/api/web/NutrientViewer.Instance.html#exportPDFWithOperations) instead, and it’ll resolve to an `ArrayBuffer` containing the final PDF.
---

## Related pages

- [PDF editing toolbar and UI](/guides/web/features/document-editor-ui.md)
- [Add images to PDFs using JavaScript](/guides/web/editor/add-image.md)
- [Add Bates numbering in PDFs using JavaScript](/guides/web/editor/add-bates-number.md)
- [Add pages to PDFs using JavaScript](/guides/web/editor/add-page.md)
- [Process documents via Document Engine or DWS API using JavaScript](/guides/web/editor/backend-processing.md)
- [PDF content editing API for Web](/guides/web/editor/content-editor-api.md)
- [Edit PDF text using our JavaScript content editor](/guides/web/editor/edit-text.md)
- [Headless PDF editor](/guides/web/features/document-editor.md)
- [JavaScript PDF editor library](/guides/web/editor.md)
- [Replace text in PDFs using JavaScript](/guides/web/editor/replace-text.md)
- [Merge PDF files using JavaScript](/guides/web/editor/merge-or-combine.md)
- [Split PDFs using JavaScript](/guides/web/editor/split.md)

