Components / PDF Viewer

Documents and fields

PDF Viewer

Shows a PDF page by page in the browser with pdf.js, with an overlay layer for fields. You pass in pdf.js.

  • @signnative/ui
  • MIT
  • Client only · no backend

The examples use a synthetic PDF made in your browser. Nothing is uploaded.

Theme
The CSS variables this sets
:root {
  --signing-accent: #3157e8;
  --sig-accent: #3157e8;
  --sig-accent-soft: color-mix(in oklab, #3157e8 14%, white);
  --sig-radius: 8px;
  --radius-control: 8px;
  --radius-panel: 12px;
  --font-sans: var(--font-inter), ui-sans-serif, system-ui, sans-serif;
}

In the signer page kit, set the accent with accentProps(accent) on the element around the surface; it sets data-signing-accent and --signing-accent. The secure elements take the same values as a checked appearance object instead.

Pages, fitted to the container

Pages are drawn as they scroll into view. onPageChange reports the current page.

current page: 1

Loading document…

Clicks and an overlay

onPageClick gives fractions of the page; renderOverlay draws on top of it in the same unit.

Click the page: no clicks yet

Loading document…

Loading

data={null} shows the loading state.

Loading document…

Installation

npx shadcn@latest add <site>/r/pdf-viewer.json

Not published yet

Not published yet. The registry item exists in packages/ui/registry.json but is not served yet.

API

className and children are left out: every component that takes them passes them on.

PdfViewer

NameTypeDefaultDescription
dataArrayBuffer | Uint8Array | nullThe PDF. Copied, so your buffer stays usable. null shows the loading state.
pdfjsPdfjsLib | (() => Promise<PdfjsLib>)pdf.js (pdfjs-dist 4 or later), or a function that loads it. The package does not import it.
workerSrcstringWhere the browser gets pdf.worker.min.mjs.
assetsUrlstringBase URL of pdf.js's standard_fonts/, cmaps/, wasm/ and iccs/ folders, for PDFs that need them.
pageWidthnumberWidth of every page in CSS pixels. Left out, pages fit the container.
maxWidthnumber820Widest a page gets when it fits the container.
textLayerbooleantrueThe page's text, invisible over the drawing, so it can be read aloud, selected and searched.
onPagesMeasured(sizes: PdfPageSize[]) => voidOnce per document: every page's size in PDF points, rotation applied.
onPageChange(page: number) => voidWhen another page becomes the current one.
renderOverlay(page, size) => ReactNodeDraws on top of a page, for example fields. Place children with fractions of the page.
onPageClick(page: number, x: number, y: number) => voidA click on a page, at fractions from its top-left corner.
labelsPartial<PdfViewerLabels>EnglishEvery text, for translation.

Accessibility

  • The viewer has a name with the page count. Page Up and Page Down go to the previous and next page.
  • The text layer lets screen readers read the page and lets people select and search text.