Skip to content
React PDF Viewer

Search

Events

React to the document loading, pages rendering and the user navigating, for analytics, logging or your own UI.

Basics

Pass callbacks to hear what the viewer is doing.

CallbackCalled withWhen
onDocumentLoad{ numPages, fingerprint }A document finished loading
onPageRender{ page, scale, width, height, durationMs }A page finished rendering
onPageChange, onScaleChange, onRotationChange, onFullscreenChangethe new valueThe user or your code changed it; see Controlled state
onErrorPdfViewerErrorSomething failed; see Error states
onDownload, onPrintthe file, or nothingBefore saving or printing; return false to take over
onHttpErrorResponseA URL source returned a non-2xx status

fingerprint identifies the document’s content, which is handy as a cache or analytics key. Callbacks can change between renders without reloading anything.

Customization

Use render measurements to drive your own UI, such as a status bar.

See the customization guide.

Advanced / escape hatch

PdfPageCanvas has its own onRender and onError for headless layouts.

Limitations

  • No scroll or selection events. The viewer does not report scroll position or text selection. Workaround: listen on the document area yourself (.rpv-viewport) or use document.getSelection() with the text layer.
  • onPageRender fires often. It fires after every render, including re-renders after zoom and resize. Workaround: debounce it before sending analytics.

API

  • PageRenderInfo — Details of a completed page render, passed to onPageRender and onRender: the page, the scale used, its size and the time it took.