@stesura/pdf-export-server
Server side of PDF export: loads the export page in headless Chromium, prints
it and assembles the PDF. Node only; the browser side is
@stesura/pdf-export-client, and the
PDF export guide covers setup, egress rules and
limits.
renderDocToPdf
Launches a browser, renders one doc and closes the browser. Takes
RenderDocToPdfArgs (RenderOptions plus headless) and resolves to the PDF
bytes. For repeated renders, keep an exporter from createPdfExporter.
RenderDocToPdfArgs
createPdfExporter
Keeps one Chromium for many renders, each in a fresh context and page, so
nothing carries over between exports. The browser launches on the first
render (warmup() launches it early) and relaunches if it crashes. Only the
process stays warm: request interception disables Chromium’s HTTP cache.
Concurrent render calls are safe but compete for CPU in one browser; queue
them, or run one exporter per worker. Every render is bounded by the timeouts
and caps in RenderOptions, and signal aborts it.
| Name | Type | Default |
|---|---|---|
options.headless | booleanLaunch headed (for debugging). Defaults to headless unless PDF_EXPORT_HEADED=1. |
CreatePdfExporterOptions
| Name | Type | Default |
|---|---|---|
headless | booleanLaunch headed (for debugging). Defaults to headless unless PDF_EXPORT_HEADED=1. |
PdfExporter
RenderOptions
ExportDocJSON
| Name | Type | Default |
|---|---|---|
type | string |
buildRequestPolicy
Parameters:| Name | Type | Default |
|---|---|---|
exportPageUrl | string | |
allowedHosts | string[] |
RequestDecision
sanitizeFileName
Parameters:| Name | Type | Default |
|---|---|---|
name | string |
contentDispositionAttachment
Parameters:| Name | Type | Default |
|---|---|---|
fileName | string |
resolveExportPageOrigin
Parameters:| Name | Type | Default |
|---|---|---|
configuredOrigin | string | |
requestOrigin | string |
readPdfExportRequest
Reads and validates a { doc, fileName? } body from the request stream. Use it
instead of await request.json(), which buffers the whole body before any cap
applies; this stops reading at maxBytes. Throws PdfExportRequestError,
whose status is the one to answer with: 413 for too large, 400 for
malformed.
| Name | Type | Default |
|---|---|---|
body | ReadableStream<Uint8Array<ArrayBufferLike>> | |
options | { maxBytes: number; } |
PdfExportRequest
| Name | Type | Default |
|---|---|---|
doc | ExportDocJSON | |
fileName | string |
readJsonBody
The same capped read without the doc validation, for a route with its own body shape.
Parameters:| Name | Type | Default |
|---|---|---|
body | ReadableStream<Uint8Array<ArrayBufferLike>> | |
__1 | { maxBytes: number; } |