A framework-agnostic, canvas-based PDF viewer for the browser. It provides the
PdfrxViewer
class and the <pdfrx-viewer> custom element, with navigation, zoom, text
selection, links, search, forms, annotations, and page editing.
npm package · Live demo · API reference · Detailed guide
transparent, so
an embedding application's surface can remain visible around PDF pages.npm install @pdfrx/viewer
import { PdfrxViewer } from '@pdfrx/viewer';
const viewer = new PdfrxViewer(document.querySelector('#viewer')!, {
engineOptions: { wasmModulesUrl: '/pdfium/' },
// Optional: let the embedding application's background show through.
backgroundColor: 'transparent',
});
await viewer.openUrl('/manual.pdf');
Opening parses and lays out the PDF, but page bitmaps continue rendering asynchronously. To open at an initial page and wait until its visible regions are sharp and painted:
await viewer.openUrl('/manual.pdf');
viewer.goToPage(12, 0);
await viewer.waitForRender();
Use
setViewTransform(transform)
instead when restoring an exact saved pan and zoom; it applies the transform
and includes the full-quality render wait. Save
currentTransform,
which is a
ViewTransformSnapshot
containing currentViewSize
metadata, to preserve the same composition when restoring into a differently
sized viewer. See
waitForRender()
and the viewer guide's complete initialization scenarios.
#viewer {
width: 100%;
height: 100vh;
}
Serve pdfium_worker.js and pdfium.wasm from
node_modules/@pdfrx/engine/assets/ at the configured wasmModulesUrl. Remote
PDF URLs must allow browser CORS access.
PdfrxViewerOptions
and the complete API reference.@pdfrx/engine ·
@pdfrx/viewer ·
@pdfrx/reactMIT
Canvas-based PDF viewer for the browser.
Use it either declaratively as the
<pdfrx-viewer>custom element (PdfrxViewerElement / definePdfrxViewerElement) or imperatively as the PdfrxViewer class. Both render pages, text selection, links, and search highlights onto a single<canvas>— there is deliberately no DOM text layer (see the architecture notes).Built on @pdfrx/engine (the rendering-engine worker client) and
@pdfrx/viewer-core(the DOM-free geometry/selection logic).Companion helpers: PdfTextSearcher for interactive search and googleFontsResolver for substituting fonts the PDF does not embed.