DocumentViewer
Primary React component. Accepts a document source, UI options, and lifecycle callbacks. Imperative control is available via ref.
Import
tsx
import { DocumentViewer, type PdfViewerRef } from "lumipdf";
import "lumipdf/styles";Props
| Prop | Type | Default | Description |
|---|---|---|---|
| source | FileSource | - | Document to open (url | file | buffer | handle). |
| theme | 'light' | 'dark' | 'auto' | 'sepia' | - | Viewer chrome theme. |
| page | number | - | Controlled page index. |
| initialZoom | number | - | Initial zoom factor. |
| showToolbar | boolean | true | Show or hide the top toolbar. |
| showSidebar | boolean | - | Control sidebar visibility when supported. |
| className | string | - | Root element class name. |
| persistKey | string | - | Optional localStorage key for viewer state. |
| onDocumentLoad | (model) => void | - | Fired when the document model is ready. |
| onError | (error) => void | - | Fired on load or runtime errors. |
| onPageChange | (page, pageCount) => void | - | Fired when the current page changes. |
| onZoom | (zoom, fitMode) => void | - | Fired when zoom or fit mode changes. |
| onSearchResult | (result) => void | - | Fired when search results update. |
| onAnnotationChange | (annotations) => void | - | Fired when annotations are added, updated, or removed. |
| onVisiblePagesChange | (pages) => void | - | Fired when the set of visible page indices changes. |
| onSelectionChange | (selection) => void | - | Fired when text selection changes. |
Ref methods
Pass a ref typed as PdfViewerRef:
| Prop | Type | Default | Description |
|---|---|---|---|
| goToPage | (index) => void | - | Navigate to a zero-based page index. |
| zoomIn / zoomOut | () => void | - | Step zoom levels. |
| setZoom | (zoom) => void | - | Set absolute zoom factor. |
| rotate | ('cw' | 'ccw') => void | - | Rotate pages clockwise or counter-clockwise. |
| search | (query) => void | - | Run a full-text search. |
| nextMatch / prevMatch | () => void | - | Move between search matches. |
| download / print | () => Promise<void> | - | Trigger download or print flows. |
| getDocument | () => DocumentModel | null | - | Return the loaded document model. |
| getAnnotations | () => Annotation[] | - | Return current annotations. |
| addAnnotation | (annotation) => void | - | Add an annotation. |
| updateAnnotation | (id, patch) => void | - | Patch an existing annotation. |
| deleteAnnotation | (id) => void | - | Remove an annotation by id. |
| setAnnotations | (annotations) => void | - | Replace the full annotation set. |
| clearAnnotations | () => void | - | Remove all annotations. |
| setActiveTool | (tool | null) => void | - | Activate an annotation tool or clear the tool. |