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).

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun addPage(width: Double = 612.0, height: Double = 792.0, content: ContentStreamBuilder): PdfBuilder

Commit a page sized width×height points from content (obtained via newPageContent). Pages appear in call order.

Link copied to clipboard
fun build(compress: Boolean = true): ByteArray

Serialize the document. When compress is true (default), each page's content stream is FlateDecode-compressed.

Link copied to clipboard

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.

Link copied to clipboard
fun page(width: Double = 612.0, height: Double = 792.0, block: ContentStreamBuilder.() -> Unit): PdfBuilder

Append a page sized width×height points (default US Letter), drawn by block. The block runs immediately, so fonts it uses are registered before build.

Link copied to clipboard
fun setInfo(title: String? = null, author: String? = null, subject: String? = null, keywords: String? = null, creator: String? = null, producer: String? = null): PdfBuilder

Set document metadata (/Info). Only non-null fields are written.