PdfViewer API
Props, callbacks and methods. Select an underlined type to explore its fields, allowed values and callback arguments.
PdfViewer14 props5 callbacks15 methods
Props14
| Name | Type | Description |
|---|---|---|
classNameOptional | string | undefined | Additional CSS classes applied to the component root. |
heightOptional | string | number | undefined | Viewer height as a CSS length or a number in pixels. |
textOptional |
| Overrides any of the default PDF viewer labels; unspecified labels keep their defaults. |
toolbarOptional |
| Omit for all tools, false for no toolbar, or choose individual groups. |
showHeaderOptional | boolean | undefined | Hide the filename/page summary header. |
renderToolbarOptional |
| Replaces the toolbar using the controller, current state and default toolbar props supplied to the callback. |
renderStatusOptional |
| Replaces loading, empty and error status content using the current viewer state. |
workerSrcRequired | string | URL of the matching pdfjs-dist/build/pdf.worker.min.mjs, served by your app. |
l10nOptional |
| PDF.js localization service for page accessibility and annotation content. |
sourceOptional |
| PDF URL, Uint8Array, ArrayBuffer or Blob. null or an omitted source shows the empty viewer. |
fileNameOptional | string | undefined | Display/download filename override for the document. |
initialPageOptional | number | undefined | Initial one-based page number, default 1; clamped to the available pages. |
initialZoomOptional |
| Initial zoom, default page-width. Use a numeric scale from 0.25 to 5 (1 = 100%), page-width or page-fit. |
documentOptionsOptional |
| Asset URLs, authentication, password and other PDF.js loading options. |
Events and callbacks5
| Name | Type | Description |
|---|---|---|
onReadyOptional |
| Receives the viewer controller so your application can navigate, zoom, search, print or download. |
onLoadOptional |
| Receives pageCount and fileName when a document has loaded. |
onPageChangeOptional |
| Receives the current one-based page number when it changes. |
onZoomChangeOptional |
| Receives the selected zoom mode/value and the resolved numeric scale. |
onErrorOptional |
| Receives document loading, worker or viewer operation errors. |
Methods15
| Name | Signature | Description |
|---|---|---|
PdfViewerController.setPrintTitle |
| Update translated print-frame accessibility text without reloading the PDF. Available through |
PdfViewerController.retry |
| Retries loading the last source after an error. Available through |
PdfViewerController.setCallbacks |
| Update event handlers without recreating the document or its worker. Available through |
PdfViewerController.subscribe |
| Subscribes to viewer state changes; returns an unsubscribe function. Available through |
PdfViewerController.attach |
| Initializes the viewer in its container before loading a document. Available through |
PdfViewerController.load |
| The latest source wins. Empty/null clears the document. Failures are exposed in snapshot/onError. Available through |
PdfViewerController.goToPage |
| Navigates to a one-based page number, clamped to the document page count. Available through |
PdfViewerController.setZoom |
| Applies a numeric scale or page-width/page-fit mode when a document is ready. Available through |
PdfViewerController.rotate |
| Rotates all pages clockwise by 90 degrees. Available through |
PdfViewerController.search |
| Searches the document; previous selects search direction and again continues to the next match. Available through |
PdfViewerController.clearSearch |
| Closes the search state and removes match highlighting. Available through |
PdfViewerController.download |
| Downloads the currently loaded PDF. Available through |
PdfViewerController.print |
| Prepares and opens the print view for the loaded PDF. Available through |
PdfViewerController.cancelPrint |
| Cancels an in-progress print preparation. Available through |
PdfViewerController.destroy |
| Releases the document, worker, listeners and viewer resources. Available through |