API reference
Generated reference for every public component, hook, function and type.
Every page in this section is generated from the TypeScript declarations and TSDoc comments of @kingtech/react-pdf-viewer, so it always matches the published types. Capability pages explain when to use each symbol; these pages list everything it accepts.
Components
PdfPageCanvas
Renders a single PDF page: cancellable, double-buffered, HiDPI and pixel-capped, with optional text and annotation layers.
PdfToolbar
The default toolbar: zoom, page navigation, fullscreen, rotate, download and print, on one row.
PdfViewer
A PDF viewer: one page at a time with a toolbar for zoom, navigation, fullscreen, rotation, download and print.
Hooks
useControllableState
The value / defaultValue / onValueChange pattern as a hook: the one behind every controlled prop of the viewer.
usePdfDocument
Loads a PDF document. Every source change aborts the previous fetch, discards its result and destroys the previous document; unmounting does the same.
Functions
configurePdfJs
Configures PDF.js for every viewer instance. Call it once at startup, before the first viewer mounts. Calls merge with previous configuration.
Types
defaultLabels
The default English labels for every user-visible string and accessible name. Override any subset with the labels prop.
FitOptions
Constrains a rendered page to a box: fit its width, its height or both, and choose whether it may grow beyond its natural size.
FullscreenMode
How fullscreen is presented: the browser Fullscreen API, a full-viewport overlay, or layout only while the parent presents it.
LabelContext
Helpers passed to label functions, such as locale-aware number formatting, so custom labels follow the viewer's locale.
PageHighlight
Search highlighting for one page's text layer: the query to mark, and which of the page's matches is the selected one.
PageRenderInfo
Details of a completed page render, passed to onPageRender and onRender: the page, the scale used, its size and the time it took.
PdfDocumentStatus
Lifecycle status of a document load: idle without a source, loading, ready with a document, or error with a PdfViewerError.
PdfJsConfig
Global PDF.js configuration shared by every viewer: how the module is loaded, the worker, and the URLs of its assets.
PdfJsDocumentOptions
Per-instance options forwarded to pdfjs-dist's getDocument (for example cMapUrl, standardFontDataUrl or verbosity). Source-related options are managed by the viewer.
PdfJsModule
The pdfjs-dist module namespace, as returned by the loader of configurePdfJs to supply a specific build.
PdfPageCanvasProps
Props for PdfPageCanvas: the document and page to render, its scale, rotation and fit, the optional layers and the render callbacks.
PdfRequestOptions
Controls how string and URL sources are fetched: extra fetch options, a replacement fetcher and the handling of HTTP errors.
PdfSource
A PDF document source: a URL for the viewer to fetch, or a file or bytes that are already in memory.
PdfToolbarProps
Props for PdfToolbar: the viewer API it controls, its labels and configuration, the compact layout and the page indicator slot.
PdfViewerApi
Imperative viewer API, available through ref and passed to renderToolbar. Values are a snapshot of the render that produced the object.
PdfViewerError
A typed viewer error. Aborted loads and canceled renders are never reported as errors.
PdfViewerErrorCode
Machine-readable category of a PdfViewerError, for handling failures such as a missing password or an HTTP error in code.
PdfViewerLabels
Every user-visible string and accessible name. Defaults are English; override any subset through the labels prop.
PdfViewerProps
Props for PdfViewer. Every piece of state supports the value / defaultValue / onChange trio.
Rotation
Clockwise rotation in degrees, relative to the page's natural orientation.
SetControllableState
Setter returned by useControllableState; accepts a value or an updater function.
ToolbarAction
Identifies a toolbar control, for choosing which controls the toolbar shows and in which order through ToolbarConfig.
ToolbarConfig
Toolbar customization: where the toolbar sits, which controls it shows and in which order, and which it hides on narrow screens.
UseControllableStateOptions
Options for useControllableState: the controlled value, the initial value while uncontrolled, and the change callback.
UsePdfDocumentOptions
Options for usePdfDocument. Changes apply on the next load, except password.
UsePdfDocumentResult
State returned by usePdfDocument: the load status, the document once ready, its page count, the error and a reload function.
Settings
CSS variables
Every custom property the stylesheet reads, with its fallback value. Set them on the viewer or any ancestor.
rpv-theme-auto
Automatic preset: add className="rpv-theme-auto" to apply the dark values only when the operating system prefers a dark color scheme.
rpv-theme-dark
Dark preset: add className="rpv-theme-dark" to the viewer to apply these values.
Commands
Keyboard shortcuts
Keys the component handles, generated from @shortcut tags next to the implementation.