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.
| Callback | Called with | When |
|---|---|---|
onDocumentLoad | { numPages, fingerprint } | A document finished loading |
onPageRender | { page, scale, width, height, durationMs } | A page finished rendering |
onPageChange, onScaleChange, onRotationChange, onFullscreenChange | the new value | The user or your code changed it; see Controlled state |
onError | PdfViewerError | Something failed; see Error states |
onDownload, onPrint | the file, or nothing | Before saving or printing; return false to take over |
onHttpError | Response | A 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 usedocument.getSelection()with the text layer. onPageRenderfires 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.