Skip to Content
API Referencepdf-viewer-react

@stesura/pdf-viewer-react

Renders an embedded PDF file’s own pages in the document, with react-pdf . Without it every PDF file node is a card with a link. The File uploads guide covers setup, the host allowlist and export behaviour.

Entry pointContents
.createPdfViewer, DEFAULT_LIMITS, PdfPreview.
/stylesThe preview stylesheet. Import it once; without it the preview doesn’t scroll.
pdf-viewer-assets (bin)Copies pdf.js’s worker, cMaps, standard fonts and WASM into a public directory.

createPdfViewer(options)

Returns a StesuraUIExtension with the pdfPreview capability, the rail of file controls and the file context-menu items. Create it once, at module scope, and mount it on both the editor and the export page.

import { createPdfViewer } from "@stesura/pdf-viewer-react"; const pdfViewer = createPdfViewer({ assets: { workerSrc: "/pdfjs/pdf.worker.min.mjs", cMapUrl: "/pdfjs/cmaps/", standardFontDataUrl: "/pdfjs/standard_fonts/", wasmUrl: "/pdfjs/wasm/", }, });

CreatePdfViewerOptions

OptionType
assetsPdfPreviewAssetsRequired. URLs your app serves pdf.js’s files from: workerSrc, plus the optional cMapUrl, standardFontDataUrl, wasmUrl and iccUrl directories (with trailing slashes).
limitsPartial<PdfPreviewLimits>Overrides for DEFAULT_LIMITS.

Both types are in @stesura/core/types.

DEFAULT_LIMITS

{ maxPages: 500, maxBytes: 50 * 1024 * 1024 }. A preview draws at most maxPages pages and says how many are left; a file whose Content-Length is over maxBytes isn’t loaded. 50 MiB matches the PDF export’s maxEmbedBytes.

PdfPreview

The preview component that createPdfViewer registers as its renderer. It takes PdfPreviewProps (from @stesura/core/types) plus assets and full limits. Exported for hosts that build their own pdfPreview capability.

pdf-viewer-assets

npx pdf-viewer-assets --out public/pdfjs

Copies the files from the installed pdfjs-dist. Run it from predev/prebuild: the worker must match the installed pdf.js version.

Theming

VariableDefault
--stesura-pdf-surround#24262bBackground around the pages.
--stesura-pdf-surround-foreground#d4d4d8Status text and control icons on that background.
--stesura-pdf-scrollbarrgb(255 255 255 / 0.28)Scrollbar thumb.
--stesura-pdf-gutter44pxLeft gutter that holds the file controls.
Last updated on