useSetPageRotation

Returns a function that sets the rotation of pages, one or several at once as a single undo step.

const setPageRotation = useSetPageRotation()

setPageRotation(pageIdOrPageIds, rotation)
  • rotation is in degrees, clockwise, and must land on a quarter turn: 0, 90, 180, or 270. Values outside 0..360 are normalized first, so -90 and 450 are valid; anything not on a quarter turn throws InvalidInputError.
  • The rotation is absolute, not added to the current one. To rotate relative to the current angle, read the page's rotation from usePages first.
  • Every id must identify an existing page, or the call throws InvalidInputError; with no document loaded, it throws DocumentNotLoadedError.

Example

import { usePages, useSetPageRotation } from '@sdk-pdf/react'

function useRotatePageClockwise() {
  const pages = usePages()
  const setPageRotation = useSetPageRotation()

  return (pageId: string) => {
    const page = pages.find((page) => page.id === pageId)
    if (page) setPageRotation(pageId, page.rotation + 90)
  }
}

On this page