pdfAsync
Suspend variant of pdf that runs a preflight pass before rendering, resolving every com.conamobile.pdfkmp.node.LazyNode in the document tree. Use this when the DSL contains nodes whose payload is fetched through a suspend API — the typed Res.drawable.X overloads in :pdfkmp-compose-resources are the canonical example.
The DSL block stays synchronous: every container scope (page, column, row, …) is the same shape as in pdf. Only the resource-loading extension functions enqueue a LazyNode whose suspend resolver is awaited here, before the layout engine ever sees the tree.
The whole pipeline — DSL evaluation, preflight, layout, rendering, and encoding — runs on Dispatchers.Default, so calling this from the main thread does not block UI. Callers that need a different dispatcher (a single-threaded test scope, an existing background pool) can wrap the call in their own withContext(...) — the inner withContext switch to Default is a no-op when the outer context is already Default.
Calling the synchronous pdf with deferred nodes throws at render time — the error message points back to this entry point.
Example:
suspend fun report(): PdfDocument = pdfAsync {
page {
drawable(Res.drawable.logo, width = 64.dp) // sync DSL,
drawable(Res.drawable.cover_photo, width = 480.dp) // async load
}
}Parameters
backend used to encode the document; same default and override semantics as pdf.
DSL configuration applied to a fresh DocumentScope.