# PDFDocument.fromUrl()

```ts
static fromUrl(url: string, options?: OpenUrlOptions): Promise<PDFDocument>
```

Load a PDF from a URL (handles CORS errors). A same-origin URL sends the cookie by default (`credentials: 'same-origin'`). A cross-origin one needs `credentials: 'include'`, and the server must then answer the page's exact origin and `Access-Control-Allow-Credentials: true` — a wildcard origin fails as `CORS_ERROR`. A `401` or `403` rejects with `NETWORK_ERROR`; its `message` ends in the status (`HTTP 401`). A token that must be refreshed per request is the host's to fetch: download the bytes with your own request and pass them to `fromBytes`. See [Document features](https://kernstra.com/docs/web-sdk/guides/document-features).

- Kind: static method
- Since: 1.0.0

| Parameter | Type | Description |
| --- | --- | --- |
| `url` | `string` | The URL to fetch. |
| `options?` | `OpenUrlOptions` | `{ password?, signal?, headers?, credentials? }`. `password` opens an encrypted file; `signal`, `headers` and `credentials` go to `fetch()` as given, which reaches a protected URL (an `Authorization` header, or `credentials: 'include'` for the session cookie on a cross-origin host). The headers are read once, at the call. |

Returns `Promise<PDFDocument>`

Throws:

- `ABORTED` — the `signal` was aborted.
- `CORS_ERROR` — the server did not allow the page's origin.
- `NETWORK_ERROR` — the request failed, including `401` and `403`.
- `NOT_INITIALIZED` — `Kernstra.init()` has not resolved.
- `FORMAT_ERROR` — not a PDF, or a corrupt one.
- `PASSWORD_ERROR` — a password is required, or the one supplied is wrong.
- `SECURITY_ERROR` — encrypted with a security handler the SDK cannot open.
- `LICENSE_REQUIRED` — opened under a stopped license (paused, revoked, expired, a copied or forged key): no document opens.
- `OUT_OF_MEMORY` — the SDK could not allocate the memory the file needs.
- `ENGINE_FAILED` — the SDK stopped on an unrecoverable fault (fatal).

```ts
const doc = await PDFDocument.fromUrl('/api/documents/123', {
  headers: { Authorization: 'Bearer ' + token },
});
```

Part of [PDFDocument](https://kernstra.com/docs/web-sdk/api/pdfdocument) in the Kernstra Web SDK 1.0.0 API reference.

Web page: https://kernstra.com/docs/web-sdk/api/pdfdocument/fromurl
