usePageDuplicate

Returns a function that duplicates a page, with all its content, and resolves with the new page's id.

const duplicatePage = usePageDuplicate()

const newPageId = await duplicatePage(sourcePageId, insertAfterPageId?)
  • Without insertAfterPageId, the duplicate is inserted right after the source page.
  • The function is asynchronous because the source page's content may not be loaded yet.
  • Both ids must identify existing pages, or the call throws InvalidInputError; with no document loaded, it throws DocumentNotLoadedError.

Example

import { usePageDuplicate, useScrollToPage } from '@sdk-pdf/react'

function useDuplicateAndShow() {
  const duplicatePage = usePageDuplicate()
  const scrollToPage = useScrollToPage()

  return async (pageId: string) => {
    const newPageId = await duplicatePage(pageId)
    scrollToPage(newPageId, { behavior: 'smooth' })
  }
}

On this page