DocumentScope

Receiver of pdf { ... }. Top-level entry of the DSL.

A document is a sequence of pages plus optional metadata, plus document- wide defaults inherited by every page. Pages are added in source order; the renderer respects that order exactly.

The document-wide defaults — defaultTextStyle, defaultPagePadding, defaultPageBreakStrategy — are how you configure typography and frame once and have every subsequent page inherit those values. Override them per-page on the PageScope when you need a different look for a single page.

Custom fonts referenced anywhere in the document are detected automatically from the node tree, but you may also pre-register them with registerFont to control the order or to register a font that no current element uses directly.

Properties

Link copied to clipboard

Default page break strategy inherited by every page unless the page overrides PageScope.pageBreakStrategy. Defaults to PageBreakStrategy.MoveToNextPage, which is the safer choice — change to PageBreakStrategy.Slice for documents where partial display of children is acceptable.

Link copied to clipboard

Default page margins inherited by every page unless the page overrides PageScope.padding. Defaults to Padding.Default (40 dp on every side) which produces a comfortable printed-document look.

Link copied to clipboard

Default text style inherited by every page unless overridden inside the page block. Mutate this to set document-wide typography (default font, color, line height, …).

Functions

Link copied to clipboard
fun attachment(fileName: String, bytes: ByteArray, mimeType: String = "application/octet-stream", description: String? = null)

Embeds a file into the document. Repeatable — each call adds another attachment in source order. Only honoured by the JVM/Desktop backend; silently skipped on iOS and Android (see PdfAttachment).

Link copied to clipboard
fun encryption(encryption: PdfEncryption)

Password-protects the document with a pre-built PdfEncryption. Useful when the configuration is assembled elsewhere; equivalent to the encryption builder overload.

fun encryption(block: EncryptionScope.() -> Unit)

Password-protects the document. Calling this more than once replaces the previous configuration. See PdfEncryption for the per-platform support matrix (full on JVM/Desktop, partial on iOS, no-op on Android).

Link copied to clipboard
fun metadata(block: MetadataScope.() -> Unit)

Configures document metadata (title, author, …). Calling this more than once replaces any previous values — fields not set in the latest call become null.

Link copied to clipboard
fun page(size: PageSize = PageSize.A4, block: PageScope.() -> Unit)

Adds a page to the document.

Link copied to clipboard
fun pdfA(enabled: Boolean)

Requests best-effort PDF/A-2b conformance for the document. Equivalent to setting MetadataScope.pdfACompliance inside metadata { }, but survives across metadata { } calls (like encryption and attachment) and wins over the value set there.

Link copied to clipboard

Registers a custom TTF/OTF font with the document so that it can be referenced by PdfFont.Custom. Fonts referenced through a TextStyle are picked up automatically; this method is for the rare case where you want to ensure a font is bundled even if no current element uses it.