Skip to content
Sign in
KnowledgePDF viewerMenu

PDF viewerPro

Thumbnails, page jump, zoom, find in document, highlights and a toolbar on selected text to ask about a passage.

ProA five page refund policy with thumbnails, find, zoom and a saved highlight; select text to ask about it.

Installation

$ pnpm dlx shadcn@latest add @chatcn-pro/pdf-viewer

Usage

tsx
import { PdfViewer } from "@/components/ui/chatcn/pro/pdf-viewer"

<PdfViewer document={policy} onAsk={(question, { text, page }) => ask(question, text, page)} />

Pages render from the text your parser extracted, laid out as the printed page in em units so every zoom is the same page, or from page images you render on the server. No PDF library ships to the browser. Highlights are controlled or uncontrolled; Ask uses the free selection-toolbar. handleRef exposes scrollToPage and scrollToSpan for a parent.

Examples

States

ProOpening, a password protected file, no pages, and a narrow panel at 150% on page 4.

Props

PropTypeNotes
document{ title, filename?, pages }Pages have blocks (text) or an image
page, defaultPage, onPageChangenumberFollows scrolling
zoom, defaultZoom, onZoomChangenumber | "fit"1 is 100%. Default fit
spans, activeSpanId, onSpanClickPdfSpan[]Cited passages by quote or rects
highlights, defaultHighlights, onHighlightsChangePdfHighlight[]{ id, page, quote }
onAsk(question, { text, page }) => voidAdds Ask to the selection toolbar
loading, error, onRetryOpening and failure states
handleRefRef<PdfViewerHandle>Imperative jumps

Keyboard

KeyAction
Ctrl or Cmd FFind in document
Enter, Shift EnterNext and previous result
Escape in findClear the search
Page Up, Page Down, arrowsScroll the pages
Tab after selecting textMoves into the selection toolbar

Accessibility

  • Pages are labeled groups; thumbnails are buttons named Page 3, with the count of marks on it.
  • The result count is a polite live region. No results is said in words.
  • Search and page inputs have labels; the zoom button names the current zoom.

Motion

Thumbnail and highlight jumps scroll smoothly; find and page entry jump instantly. Zoom keeps your reading position. Reduced motion makes every scroll instant.