# useLoadPdf

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



Loads a PDF document and reports the load state.

```ts
const [loadState, loadPdf] = useLoadPdf()
```

## Load state [#load-state]

`loadState.status` is one of:

| Status      | Meaning                                                       |
| ----------- | ------------------------------------------------------------- |
| `'initial'` | No document is loaded, no loading in progress, no error.      |
| `'loading'` | A document is loading.                                        |
| `'ready'`   | A document is loaded; the PDF application UI can be rendered. |

## loadPdf [#loadpdf]

```ts
loadPdf(pdfFileContent: Uint8Array, options?: { password?: string }): Promise<void>
```

* The document reads from the given buffer for its whole lifetime, and anything else touching the buffer can detach its `ArrayBuffer` (another `loadPdf` call, a transfer to a worker), making every later document read throw. If you intend to reuse the buffer, pass a copy: `loadPdf(data.slice())`.
* Loading replaces the current document: it's unloaded as soon as loading starts, together with everything derived from it (see [useResetPdf](https://sdk.pdf.net/docs/v1/reference/useResetPdf)). When loading fails, the state returns to `'initial'`.
* For an encrypted document, pass `password`. Without one, the empty password is tried, as the PDF specification prescribes (some documents open with it despite being encrypted). When the password is missing or wrong, the promise rejects with `InvalidPasswordError`: catch it and ask the user, then call `loadPdf` again.

## Example [#example]

See [Getting started](https://sdk.pdf.net/docs/v1/guides/getting-started) for a complete loading flow with a file input, the loading state, and the password prompt.

