CONTENT_POLICY_PRESET

The common content policy combinations, ready to pass to PdfProviders as initialContentPolicy or to useSetInteractionMode.

KindPDF_PRINTERPDF_VIEWERPDF_EDITOR
textreadonlyreadonlyeditable
annotationsreadonlyreadonlyeditable
linksinteractiveinteractiveeditable
widgetsreadonlyinteractiveeditable

In short: PDF_PRINTER shows the document as it would print, with links still clickable; PDF_VIEWER additionally lets users fill forms; PDF_EDITOR makes everything editable.

Content policy

A ContentPolicy is a plain object setting a permission level for each content kind. A preset is one; write your own for other combinations.

KindCoversLevels
textThe text paragraphs.'hidden' | 'readonly' | 'editable'
annotationsAll annotations except links and form widgets.'hidden' | 'readonly' | 'editable'
linksThe link annotations.'hidden' | 'interactive' | 'editable'
widgetsThe form widgets.'hidden' | 'readonly' | 'interactive' | 'editable'

The levels:

  • hidden: the blocks are not shown and can't be selected. They stay in the document and in the saved PDF.
  • readonly: the blocks are shown and can't be changed.
  • interactive: links can be followed and form fields filled, but the blocks can't be edited.
  • editable: the blocks can be selected, moved, resized, and deleted, and text can be edited.

Per-block levels

Each kind takes either a level, applied to all its blocks, or a function returning the level for a block by its id (a ContentPolicyValue). Use it to hide or lock individual blocks, such as the form fields a user is not allowed to fill.

  • The function is called with session-scoped block ids, such as the widget ids from useWidgets.
  • The SDK calls the function again only when it receives a new policy with a new function. When the answer for a block changes, pass a new policy with a new function to useSetInteractionMode; mutating the data the function reads doesn't update the page.

Example

import { useMemo } from 'react'
import {
  CONTENT_POLICY_PRESET,
  ContentPolicy,
  useSetInteractionMode,
} from '@sdk-pdf/react'

const selectTool = { type: 'select' } as const

function useLockFields(lockedWidgetIds: ReadonlySet<string>) {
  const setInteractionMode = useSetInteractionMode()

  // A new function each time the locked set changes, so the SDK picks up the new answers.
  const contentPolicy = useMemo<ContentPolicy>(
    () => ({
      ...CONTENT_POLICY_PRESET.PDF_VIEWER,
      widgets: (widgetId) => (lockedWidgetIds.has(widgetId) ? 'readonly' : 'interactive'),
    }),
    [lockedWidgetIds]
  )

  return () => setInteractionMode(selectTool, contentPolicy)
}

On this page