# useScrollToPage

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



Returns a function that scrolls the viewport to a page.

```ts
const scrollToPage = useScrollToPage()

scrollToPage(pageId, options?)
```

* `pageId` is an id obtained from [usePages](https://sdk.pdf.net/docs/v1/reference/usePages). An unknown or deleted id throws `InvalidInputError`; with no document loaded, the call throws `DocumentNotLoadedError`.
* `options` controls where the page lands in the viewport:

| Option       | Values                                       | Default     | What it does                                       |
| ------------ | -------------------------------------------- | ----------- | -------------------------------------------------- |
| `behavior`   | `'auto' \| 'smooth' \| 'instant'`            | `'auto'`    | The scroll animation, as in native scrolling.      |
| `vertical`   | `'top' \| 'center' \| 'bottom' \| 'nearest'` | `'top'`     | Which vertical viewport edge the page aligns to.   |
| `horizontal` | `'left' \| 'center' \| 'right' \| 'nearest'` | `'nearest'` | Which horizontal viewport edge the page aligns to. |

The edges are physical: they don't change with the writing mode or text direction.

## Example [#example]

```tsx
const scrollToPage = useScrollToPage()

scrollToPage(page.id, { behavior: 'smooth', vertical: 'center' })
```

