PdfViewer
A clean PDF reader with page navigation, zoom, fit to width and selectable text.
Installation
npx dafink-ui add pdfviewerAlso installs: Button, Select, Spinner, Icons
Requires: pdfjs-dist
Demo
Quarterly Report
of –
Loading PDF…
Props
| Name | Type | Default | Description |
|---|---|---|---|
| src | string | Uint8Array | None | URL of the PDF, or its bytes. Required. Cross-origin URLs need CORS headers. |
| title | string | None | Optional heading shown on the left of the toolbar. Also names the scrolling region; falls back to "PDF document" when omitted. |
| initialPage | number | 1 | Page to scroll to once the document has loaded. |
| height | number | string | '40rem' | Height of the viewer. Pages scroll inside it. |
| toolbarTarget | HTMLElement | null | None | Where the zoom and page controls render. Omit for the built-in toolbar row; pass an element to portal the controls into your own toolbar (no title or border of their own); pass null to hide them. |
| onLoad | (pageCount: number) => void | None | Called once the document has loaded. |
| onError | (error: Error) => void | None | Called when the file cannot be loaded or parsed. |
| onPageChange | (page: number) => void | None | Called when the current page changes, by scrolling, the toolbar or the page field. |
| onPageDoubleClick | (point: { page: number; x: number; y: number }) => void | None | Called on a double click with the page number and the position in PDF points from the page top-left corner. |
Accessibility
PdfViewer uses the native tab order: the toolbar controls come first, then the page area, which is a focusable scrolling region named after the title so keyboard users can read the document without a mouse. Each page is exposed as an image labelled "Page 2 of 8", and the text layer over it is real text, so it can be selected, copied and read by screen readers. Controls that cannot act yet (before load and at the zoom limits) are disabled, and a failed load is announced with an alert.
| Key | Function |
|---|---|
| Tab | Moves through the toolbar, then into the page area. |
| Enter | In the page field, jumps to the typed page. |
| ↑+↓ | Scrolls the focused page area. |
| Page Up+Page Down | Scrolls the focused page area by one screen. |
| Home+End | Jumps to the start or end of the document. |