Interface: DocumentOperation

PSPDFKit.DocumentOperation

This object determines the operation to be performed on the document.

Available operations:

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

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

  • { 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 the 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 duplicated page will be inserted after the page being duplicated.

  • { 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 the pages specified in the pageIndexes array by the degrees indicated in rotateBy.

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

Removes the pages specified in the pageIndexes array.

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

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

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

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

type AddPageConfiguration = {
  backgroundColor: PSPDFKit.Color,
  pageWidth: number,
  pageHeight: number,
  rotateBy: 0 | 90 | 180 | 270,
  insets?: PSPDFKit.Geometry.Rect
}

Example

// Rotate page 0 90 degrees clockwise
instance.applyOperations({
  type: "rotatePages",
  pageIndexes: [0],
  rotateBy: 90
});