Your first viewer
A complete viewer with selectable text, page and zoom controls, and explicit layout.
Complete the installation first. This example imports the pdf-setup.ts you created there and loads public/sample.pdf. In Next.js, render it through the browser-only wrapper from that guide.
A viewer you can build on
CurrentPage and CurrentZoom are editable inputs, so they need labels. The zoom buttons have no default text; supply their children. CurrentPage commits when the input loses focus or you press Enter.
How the pieces fit
Pass one Page template to Pages. It supplies the page number; you do not map over the document yourself. Page numbers in Lector's public navigation APIs start at 1.
Root only mounts its children after the document and page viewports are ready. Components using usePdf, usePdfJump, or other viewer hooks must be descendants of Root. Page-specific layers and usePDFPageNumber also need a Page ancestor. A hook in the same component that returns Root is still outside that provider.
Give the pages room to scroll
Pages defaults to height: 100% and owns its scrolling. Give its parent a definite height. With a toolbar, use a flex column and put Pages in a flex: 1; min-height: 0 wrapper, as above. In a sidebar layout, also set min-width: 0 on the viewer column.
Avoid overriding Page dimensions or applying your own scale transform: Lector uses its viewports to align canvas, text, and highlights.
Choose your layers
| Layer | Adds | Guide |
|---|---|---|
CanvasLayer | Visible PDF content | Basic example |
TextLayer | Selection and copying when the PDF contains text | Text selection |
AnnotationLayer | Existing PDF links and form widgets | Links, forms |
HighlightLayer | Rectangles from the viewer's highlights state | Highlights |
ColoredHighlightLayer | Selection color tools and colored highlights | Text selection |
Place canvas first, then text, then the interaction or highlight layers you need. Loading failures need application UI outside Root; see loading and errors.
Next, add page navigation, search, or dark mode.