PdfDriver
Per-document handle returned by a PdfDriverFactory.
A driver is stateful and single-use: produce pages one at a time with beginPage / endPage, then call finish exactly once to obtain the encoded PDF bytes. Calling any method after finish is undefined.
The expected lifecycle is:
val driver = factory.create(metadata, customFonts)
val canvas1 = driver.beginPage(PageSize.A4)
// ... draw on canvas1 ...
driver.endPage()
val canvas2 = driver.beginPage(PageSize.A4)
// ... draw on canvas2 ...
driver.endPage()
val bytes = driver.finish()Drivers are not thread-safe and must be used from a single coroutine / thread.
Properties
Functions
Releases any underlying resources without producing output. Called by the renderer when rendering fails partway through (so finish is never reached) to avoid leaking native / file handles. Must be idempotent and safe to call after finish. The default is a no-op — backends whose resources are already freed by finish (or that hold none, like the Android PdfDocument / iOS CGContext backends) need not override it; the JVM PdfBox backend overrides it to close its PDDocument.