Skip to components
DEVELOPER REFERENCE · v4.0.0

PdfViewer API

Props, callbacks and methods. Select an underlined type to explore its fields, allowed values and callback arguments.

PdfViewer14 props5 callbacks15 methods

Props14

PdfViewer props
NameTypeDescription
classNameOptionalstring | undefinedAdditional CSS classes applied to the component root.
heightOptionalstring | number | undefinedViewer height as a CSS length or a number in pixels.
textOptional
Partial<PdfViewerText>Inspect type
Overrides any of the default PDF viewer labels; unspecified labels keep their defaults.
toolbarOptional
PdfViewerToolbarConfig | undefinedInspect type
Omit for all tools, false for no toolbar, or choose individual groups.
showHeaderOptionalboolean | undefinedHide the filename/page summary header.
renderToolbarOptional
((controller: PdfViewerController, state: Readonly<PdfViewerState>, toolbarProps: PdfViewerToolbarProps) => ComponentChildren) | undefinedInspect type
Replaces the toolbar using the controller, current state and default toolbar props supplied to the callback.
renderStatusOptional
((state: Readonly<PdfViewerState>) => ComponentChildren) | undefinedInspect type
Replaces loading, empty and error status content using the current viewer state.
workerSrcRequiredstringURL of the matching pdfjs-dist/build/pdf.worker.min.mjs, served by your app.
l10nOptional
L10n | undefinedInspect type
PDF.js localization service for page accessibility and annotation content.
sourceOptional
PdfSource | null | undefinedInspect type
PDF URL, Uint8Array, ArrayBuffer or Blob. null or an omitted source shows the empty viewer.
fileNameOptionalstring | undefinedDisplay/download filename override for the document.
initialPageOptionalnumber | undefinedInitial one-based page number, default 1; clamped to the available pages.
initialZoomOptional
PdfZoom | undefinedInspect type
Initial zoom, default page-width. Use a numeric scale from 0.25 to 5 (1 = 100%), page-width or page-fit.
documentOptionsOptional
Omit<DocumentInitParameters, "data" | "url" | "worker"> | undefinedInspect type
Asset URLs, authentication, password and other PDF.js loading options.

Events and callbacks5

PdfViewer events and callbacks
NameTypeDescription
onReadyOptional
((controller: PdfViewerController) => void) | undefinedInspect type
Receives the viewer controller so your application can navigate, zoom, search, print or download.
onLoadOptional
((details: { pageCount: number; fileName: string; }) => void) | undefinedInspect type
Receives pageCount and fileName when a document has loaded.
onPageChangeOptional
((page: number) => void) | undefinedInspect type
Receives the current one-based page number when it changes.
onZoomChangeOptional
((zoom: PdfZoom, scale: number) => void) | undefinedInspect type
Receives the selected zoom mode/value and the resolved numeric scale.
onErrorOptional
((error: Error) => void) | undefinedInspect type
Receives document loading, worker or viewer operation errors.

Methods15

PdfViewer methods
NameSignatureDescription
PdfViewerController.setPrintTitle
(title: string) => voidInspect type
Update translated print-frame accessibility text without reloading the PDF.

Available through renderToolbar callback.

PdfViewerController.retry
() => Promise<void>Inspect type
Retries loading the last source after an error.

Available through renderToolbar callback.

PdfViewerController.setCallbacks
(callbacks: Pick<PdfViewerOptions, "onLoad" | "onError" | "onPageChange" | "onZoomChange">) => voidInspect type
Update event handlers without recreating the document or its worker.

Available through renderToolbar callback.

PdfViewerController.subscribe
(listener: (state: Readonly<PdfViewerState>) => void) => () => voidInspect type
Subscribes to viewer state changes; returns an unsubscribe function.

Available through renderToolbar callback.

PdfViewerController.attach
(container: HTMLDivElement) => Promise<void>Inspect type
Initializes the viewer in its container before loading a document.

Available through renderToolbar callback.

PdfViewerController.load
(source: PdfSource | null, fileName?: string) => Promise<void>Inspect type
The latest source wins. Empty/null clears the document. Failures are exposed in snapshot/onError.

Available through renderToolbar callback.

PdfViewerController.goToPage
(page: number) => voidInspect type
Navigates to a one-based page number, clamped to the document page count.

Available through renderToolbar callback.

PdfViewerController.setZoom
(zoom: PdfZoom) => voidInspect type
Applies a numeric scale or page-width/page-fit mode when a document is ready.

Available through renderToolbar callback.

PdfViewerController.rotate
() => voidInspect type
Rotates all pages clockwise by 90 degrees.

Available through renderToolbar callback.

PdfViewerController.search
(query: string, previous?: boolean, again?: boolean) => voidInspect type
Searches the document; previous selects search direction and again continues to the next match.

Available through renderToolbar callback.

PdfViewerController.clearSearch
() => voidInspect type
Closes the search state and removes match highlighting.

Available through renderToolbar callback.

PdfViewerController.download
() => Promise<void>Inspect type
Downloads the currently loaded PDF.

Available through renderToolbar callback.

PdfViewerController.print
() => Promise<void>Inspect type
Prepares and opens the print view for the loaded PDF.

Available through renderToolbar callback.

PdfViewerController.cancelPrint
() => voidInspect type
Cancels an in-progress print preparation.

Available through renderToolbar callback.

PdfViewerController.destroy
() => voidInspect type
Releases the document, worker, listeners and viewer resources.

Available through renderToolbar callback.