Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

PDF Embed

ProNew

An inline document viewer with a file header, page field, zoom, thumbnails, download and full screen, from supplied pages or the browser's own PDF viewer. Use File Embed for PDF lists and grids.

Installation

pnpm dlx shadcn@latest add @viewport/pdf-embed

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
title*string

Shown in the header and used to name the viewer.

—
srcstring

The PDF itself. Used for download, print and open; shown in the browser's own viewer when `pages` is not given.

—
pagesPdfPage[]

Rendered pages. With these the viewer draws its own toolbar, thumbnails and zoom.

—
sizenumber | string

File size in bytes, or a ready-made label such as "2.4 MB".

—
heightnumber

Height of the reading area, in pixels. It shrinks in narrow containers.

640
aspectnumber

Page width divided by page height. 0.707 is A4 portrait.

0.707
headerboolean

Show the title bar with the file name and download button.

true
toolbarboolean

Show the dark toolbar with page, zoom and full screen controls.

true
thumbnailsboolean

Offer the thumbnail sidebar.

true
defaultSidebarboolean

Start with the thumbnail sidebar open when there is room for it.

false
downloadboolean

Offer a download button. Needs `src`.

true
printboolean

Offer a print button. Needs `src`.

true
iconReact.ReactNode

Replaces the PDF mark in the header.

—
loadingboolean

Shows page placeholders while the document is being fetched.

false
errorboolean | string

Shows the error state. Pass a string to explain what went wrong.

false
onRetry() => void

Adds a Try again button to the error state.

—
onPageChange(page: number) => void

Called with the page in view, counted from 1.

—
onDownload() => void—
classNamestring—

Accessibility

  • The reading area is a focusable, natively scrolling region named with the document and page; Home and End jump to the first and last page, plus and minus zoom.
  • Toolbar controls are named buttons and a labelled page field; page and zoom changes are announced politely.
  • Thumbnails are a list of buttons with the current page marked.
  • Loading is a status and failure is an alert; invalid PDF URLs never reach iframe, print or download controls.
  • Jumping between pages does not smooth-scroll under reduced motion.