streamFlow
Function streamFlow
streamFlow(pdf: PDFDocument, writable: WritableStream<Uint8Array<ArrayBufferLike>>, nodes: AsyncIterable<Node, any, any> | Iterable<Node, any, any>, options?: StreamFlowOptions): Promise<{ pageCount: number }>Render nodes as a multi-page PDF, emitting bytes to writable as
each page closes. Memory stays bounded at O(shared resources + one page in flight) regardless of total page count.
Contract:
- Embed any fonts / images BEFORE calling streamFlow. Mid-stream embedding throws.
- The iterable is consumed lazily — yield one node at a time from a generator. Materializing the whole array defeats the point.
writableis closed by streamFlow on success and aborted on failure. Don't write to it concurrently.- Header/footer callbacks receive
{ pageNumber }only. Readingctx.totalPagesthrows.
Parameters
-
pdf: PDFDocument -
writable: WritableStream<Uint8Array<ArrayBufferLike>> -
nodes: AsyncIterable<Node, any, any> | Iterable<Node, any, any> -
options?: StreamFlowOptions
The total number of pages written.