PdfBuilder
Creates a brand-new PDF from scratch, the full (non-incremental) write path.
val bytes = PdfBuilder()
.setInfo(title = "Demo", author = "KitePDF")
.page { text(StandardFont.Helvetica, 24.0, 72.0, 700.0, "Hello, world!") }
.build()Builds the object graph (catalog → page tree → pages, each with an inlined /Resources and a content stream), then serializes a complete file: header, objects, a classic xref table, and a trailer. Page content is drawn with ContentStreamBuilder; text uses the standard-14 fonts (no embedding).
Content streams are FlateDecode-compressed by default (see build).
Functions
Commit a page sized width×height points from content (obtained via newPageContent). Pages appear in call order.
Encrypt the document with the V5/AES-256 (R6, PDF 2.0) Standard Security Handler. Every string and stream is encrypted; the file opens with either password. permissions maps to the advisory /P flags. random feeds the file key, salts and per-object IVs; seed it for reproducible bytes in tests. Only AES-256 is offered on the create path: there is no reason to mint new documents with weaker legacy schemes.
A fresh ContentStreamBuilder wired to this builder's font/image resources. Pair with addPage when page drawing must be driven imperatively, e.g. from a suspend layout routine that page's synchronous block can't host. Fonts/images used here are registered when addPage commits the builder.