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

PropTypeDefaultDescription
sourceFileSource-Document to open (url | file | buffer | handle).
theme'light' | 'dark' | 'auto' | 'sepia'-Viewer chrome theme.
pagenumber-Controlled page index.
initialZoomnumber-Initial zoom factor.
showToolbarbooleantrueShow or hide the top toolbar.
showSidebarboolean-Control sidebar visibility when supported.
classNamestring-Root element class name.
persistKeystring-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:

PropTypeDefaultDescription
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.