# CONTENT_POLICY_PRESET

Source: https://sdk.pdf.net/docs/v1/reference/CONTENT_POLICY_PRESET



The common content policy combinations, ready to pass to [PdfProviders](https://sdk.pdf.net/docs/v1/reference/PdfProviders) as `initialContentPolicy` or to [useSetInteractionMode](https://sdk.pdf.net/docs/v1/reference/useSetInteractionMode).

| Kind          | `PDF_PRINTER` | `PDF_VIEWER`  | `PDF_EDITOR` |
| ------------- | ------------- | ------------- | ------------ |
| `text`        | `readonly`    | `readonly`    | `editable`   |
| `annotations` | `readonly`    | `readonly`    | `editable`   |
| `links`       | `interactive` | `interactive` | `editable`   |
| `widgets`     | `readonly`    | `interactive` | `editable`   |

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 [#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.

| Kind          | Covers                                         | Levels                                                  |
| ------------- | ---------------------------------------------- | ------------------------------------------------------- |
| `text`        | The text paragraphs.                           | `'hidden' \| 'readonly' \| 'editable'`                  |
| `annotations` | All annotations except links and form widgets. | `'hidden' \| 'readonly' \| 'editable'`                  |
| `links`       | The link annotations.                          | `'hidden' \| 'interactive' \| 'editable'`               |
| `widgets`     | The 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 [#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](https://sdk.pdf.net/docs/v1/reference/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](https://sdk.pdf.net/docs/v1/reference/useSetInteractionMode); mutating the data the function reads doesn't update the page.

## Example [#example]

```tsx
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)
}
```

