@stesura/pdf-export-client
Browser side of PDF export: the toolbar button, and the shell for the export
page the server loads. The server side is
@stesura/pdf-export-server; the
PDF export guide covers setup.
Toolbar
pdfUiExtension adds the PDF export group to the toolbar’s Export tab:
import { pdfUiExtension } from '@stesura/pdf-export-client'
<StesuraEditor uiExtensions={[pdfUiExtension]} />For a custom endpoint or file name, mount PdfExportGroup (the button in a
labelled toolbar group, which is what pdfUiExtension mounts) or the bare
PdfExportButton instead. The button posts { doc, fileName } to the endpoint
and downloads the PDF; failures, including a non-PDF response, show a toast
unless you pass onError. Both take the same props:
PdfExportButtonProps
Export page (/shell)
ExportEditorShell ({ children: ReactNode }) wraps the read-only editor on
the export route. It provides the clipping viewport, publishes
window.__stesuraPdfExport (ExportApi) and flags <body> with
data-export-ready or data-export-error once the layout has settled. The
editor stays in your app, so it keeps your plugins and extensions.
import { ExportEditorShell } from '@stesura/pdf-export-client/shell'
<ExportEditorShell>
<StesuraEditor printMode editable={false} toolbar={false} … />
</ExportEditorShell>It is on its own subpath because it loads the print stylesheet, whose @page
rule can’t be scoped and must only load on the export route. Don’t import
@stesura/pdf-export-client/print.css yourself.
The server injects the document as window.__STESURA_EXPORT_DOC__ (an
ExportPayload) before any page script runs; importing the shell types that
global. If the payload is missing, set document.body.dataset.exportError
rather than rendering nothing, or the server waits until its timeout. The
guide lists the rest of the export
page’s requirements.
Protocol types (/types)
The contract between the export page and the server, from
@stesura/pdf-export-client/types. This entry point has no React or browser
dependencies, so the server can import it.
ExportApi
ExportPayload
| Name | Type | Default |
|---|---|---|
doc | JSONContent | |
fileName | string |
ExportPageInfo
ExportLink
| Name | Type | Default |
|---|---|---|
kind | "url" | "internal" | |
rect | ExportLinkRect |
ExportLinkRect
| Name | Type | Default |
|---|---|---|
x | number | |
y | number | |
width | number | |
height | number |
ExportOutlineNode
| Name | Type | Default |
|---|---|---|
title | string | |
pageIndex | numberManifest / merged-PDF page index of the heading. | |
y | numberHeading top in page-local CSS px from the page top. | |
children | ExportOutlineNode[] |