PDF document editing library for Node.js

Nutrient Node.js SDK includes support for editing documents — rotating, merging, splitting, deleting, or adding pages — with no third-party dependencies required. It offers developers a way to quickly embed a highly configurable PDF editor in any Node.js application.

Nutrient SDKs are trusted by world’s most popular applications, including Autodesk, Disney, UBS, Dropbox, IBM, and Lufthansa. Nutrient’s powerful solutions enable seamless integration of PDF editing features into your applications, delivering reliability and efficiency to world-class enterprises.

Document operations

The instance.applyOperations() method lets you perform editing operations on a document. The method receives an array of operations to apply to the document in Instant JSON format:

Available operations

  • { type: "addPage", afterPageIndex: number, ...AddPageConfiguration }

Adds a blank page after the specified page index using the provided configuration.

type AddPageConfiguration = {
	backgroundColor: string // RGB color in CSS hex format.
	pageWidth: number,
	pageHeight: number,
	rotateBy: 0 | 90 | 180 | 270,
	insets?: number[] // Page insets in the order [top, right, bottom, left].
}
  • { type: "addPage", beforePageIndex: number, ...AddPageConfiguration }

Adds a blank page before the specified page index using the provided configuration.

  • { type: "keepPages", pageIndexes: Array<number> }

Removes all pages from the document except for the pages specified in the pageIndexes array.

  • { type: "duplicatePages", pageIndexes: Array<number> }

Duplicates the pages specified in the pageIndexes array. Each new page will be inserted after the original page.

  • { type: "movePages", pageIndexes: Array<number>, afterPageIndex: number }

Moves the pages specified in the pageIndexes array after the page specified.

  • { type: "movePages", pageIndexes: Array<number>, beforePageIndex: number }

Moves the pages specified in the pageIndexes array before the page specified.

  • { type: "rotatePages", pageIndexes: Array<number>, rotateBy: 0 | 90 | 180 | 270 }

Rotates the pages specified in the pageIndexes array by the amount of degrees set in rotateBy.

  • { type: "removePages", pageIndexes: Array<number> }

Removes the pages specified in the pageIndexes array.

  • { type: "importDocument", afterPageIndex: number, treatImportedDocumentAsOnePage: boolean, document: Blob | File | string }

Imports the provided document after the specified page index. treatImportedDocumentAsOnePage determines whether it’ll be treated as a single page for other document operations (e.g. a rotation) provided during the same call. After these operations are applied, the imported pages will behave like regular pages in the document.

The document must be provided as a Blob, a File, or a string containing the path to the document to be imported.

Flattening and importing a document with treatImportedDocumentAsOnePage set in the same operations batch isn’t supported and will raise an error.

  • { type: "importDocument", beforePageIndex: number, treatImportedDocumentAsOnePage: boolean, document: Blob | File | string }

Imports the provided document before the specified page index.

  • { type: "importDocument", beforePageIndex: number, importedPageIndexes?: ImportPageIndex, treatImportedDocumentAsOnePage: boolean, document: Blob | File | string }

Imports the specified page indexes from the provided document before the specified page index.

  • { type: "applyInstantJson", instantJson: Object }

Applies the given Instant JSON object specified in the instantJson property. To learn about Instant JSON, refer to the associated guide.

  • { type: "applyXfdf", xfdf: string, ignorePageRotation?: boolean }

Applies the given XFDF string specified in the xfdf property.

To learn about XFDF, refer to the XFDF support guide.

  • { type: "flattenAnnotations", pageIndexes?: Array<number>, annotationIds?: Array<string>, noteAnnotationOpacity?: number, noteAnnotationBackgroundColor?: string }

Flattens the annotations of the specified pages, or of all pages if none are specified.

Flattening and importing a document with treatImportedDocumentAsOnePage set in the same operations batch isn’t supported and will raise an error.

  • { type: "setPageLabel", pageIndexes?: Array<number>, pageLabel?: string }

Sets the page label of a given page index.

  • { type: "updateMetadata", metadata: { title?: string, author?: string } }

Updates metadata on the destination document.

  • { type: "cropPages", pageIndexes?: Array<number>, cropBox: number[] }

Crops the pages of the PDF document. If the pageIndexes property isn’t set, the cropping operation is applied to all pages.

instance.applyOperations([
  {
    type: "cropPages",
    pageIndexes: [1, 2],
    cropBox: [100, 100, 200, 200] // Page insets in the order [top, right, bottom, left].
  }
]);
  • { type: "addPageMargins", pageIndexes?: Array<number>, margins: number[] }

Adds margins to the pages of the document. If the pageIndexes property isn’t set, the new margins are applied to all pages. Negative numbers will shrink the page.

Content and annotations will be repositioned back to the original location on the page, and other boxes (crop, bleed, trim, art) will be adjusted to encompass the same area.

instance.applyOperations([
  {
    type: "addPageMargins",
    pageIndexes: [1, 2],
    margins: [100, 100, 100, 100] // Page margins in the order [top, right, bottom, left].
  }
]);

Free trial

Start your free trial for unlimited access and expert support.