@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 point | Contents |
|---|---|
. | createPdfViewer, DEFAULT_LIMITS, PdfPreview. |
/styles | The 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
| Option | Type | |
|---|---|---|
assets | PdfPreviewAssets | Required. URLs your app serves pdf.js’s files from: workerSrc, plus the optional cMapUrl, standardFontDataUrl, wasmUrl and iccUrl directories (with trailing slashes). |
limits | Partial<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/pdfjsCopies the files from the installed pdfjs-dist. Run it from
predev/prebuild: the worker must match the installed pdf.js version.
Theming
| Variable | Default | |
|---|---|---|
--stesura-pdf-surround | #24262b | Background around the pages. |
--stesura-pdf-surround-foreground | #d4d4d8 | Status text and control icons on that background. |
--stesura-pdf-scrollbar | rgb(255 255 255 / 0.28) | Scrollbar thumb. |
--stesura-pdf-gutter | 44px | Left gutter that holds the file controls. |