---
title: "Add margins to PDF pages using JavaScript | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/web/editor/page-manipulation/add-margins/"
md_url: "https://www.nutrient.io/guides/web/editor/page-manipulation/add-margins.md"
last_updated: "2026-05-20T14:17:14.780Z"
description: "Add custom margins to PDF pages using JavaScript with Nutrient Web SDK. Use addPageMargins operation to set left, right, top, and bottom insets programmatically."
---

# Adding margins to PDF pages using JavaScript

It’s possible to individually add margins to multiple document pages using the `addPageMargins` document operation.

This feature is only available to customers who have purchased the Document Editor component. If you want to try it, [contact our Sales team](https://www.nutrient.io/contact-sales).

## How to add margins to pages using the programmatic API

You can use [`NutrientViewer.Instance#applyOperations`](https://www.nutrient.io/api/web/NutrientViewer.Instance.html#applyOperations) to add margins to PDF document pages:

```js

await instance.applyOperations([
  {
    type: "addPageMargins",
    pageIndexes: [1, 2],
    rect: new NutrientViewer.Geometry.Inset({
      left: 10,
      top: 10,
      right: 10,
      bottom: 10
    })
  }
]);

```

If you omit the `pageIndexes` property from the code above, all the PDF document’s pages will have their margins modified.
---

## Related pages

- [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)
- [Remove pages from a PDF using JavaScript](/guides/web/editor/page-manipulation/remove.md)

