PdfDocument
A loaded PDF document. Construct with open.
val doc = PdfDocument.open(bytes) // unencrypted
val doc = PdfDocument.open(bytes, "secret".encodeToByteArray())
println("${doc.pageCount} pages, PDF ${doc.version}")
println(doc.pages[0].extractText())
// Editing returns a writer; the document itself is immutable.
val editor = doc.edit()
editor.setInfo(title = "Reviewed")
val updated: ByteArray = editor.saveIncremental()Holds the raw byte buffer plus the xref table; pages and indirect objects are resolved lazily and cached.
Thread-safe for concurrent reads and rendering after construction (T-16): object resolution parses from per-call readers and synchronizes only its caches, so multiple threads may render pages of the same document, including the same page, simultaneously.
Properties
Interactive form (AcroForm) catalog metadata. null when the catalog has no /AcroForm entry. The document carries no interactive form fields.
Article threads (/Threads). Each thread is a reading-order sequence of bead rectangles on pages. Readers use them to jump between columns in a multi-column layout. Empty list when the catalog has no /Threads.
Embedded file attachments. These are typically the document author's supplementary files: source artwork, datasets, XML schemas, etc. Empty list when the document has no /EmbeddedFiles name tree.
The document catalog (/Root in the trailer).
Document-level JavaScript scripts from /Names /JavaScript. Map keys are the script names; values are the JS source. Empty when none.
Flattened interactive-form fields (the AcroForm field tree's terminal fields, with inheritable attributes resolved). Empty when the document has no form. Drives form-filling via io.github.yuroyami.kitepdf.writer.PdfEditor.
Document /Info dictionary (title, author, dates, …). Returns an empty info object if the trailer has no /Info or it doesn't resolve.
True if open found a working password for an encrypted doc.
True if the document is encrypted.
Tagged-PDF accessibility metadata. null when the document has no /MarkInfo dict, which means it is not tagged.
Format-neutral metadata for KiteDocument viewers: /Info values, falling back to XMP where /Info is silent, plus the catalog /Lang.
Optional Content / layers metadata (read-only). null when the catalog has no /OCProperties.
Format-neutral outline for KiteDocument viewers: outlines with each destination resolved to a zero-based page index (null when unresolvable).
Document outline (bookmarks). Top-level entries from the catalog /Outlines /First chain; empty list if the document has no outline.
Initial page-layout hint (/PageLayout). PageLayout.SinglePage when absent.
Initial UI panel hint (/PageMode). PageMode.UseNone when absent.
Document permissions (ISO 32000-1 §7.6.3.2 Table 22). Always allow-all for unencrypted documents; reflects the /P bit-flags from the security handler otherwise.
Viewer-preferences hints (/ViewerPreferences). Returns PdfViewerPreferences.DEFAULT when the catalog doesn't carry the dict.
Parsed XMP metadata. Extracts the common Dublin Core / Adobe PDF / XMP-basic properties. Falls back to the trailer /Info dict when XMP is absent. Call info explicitly if you need both views.
Raw XMP metadata packet as a UTF-8 string, or null if the catalog has no /Metadata stream (or it doesn't resolve to one).
Functions
Open an incremental-update editor over this document. Edits are saved by appending to the original bytes (see PdfEditor); this document instance itself is never mutated. For AES-encrypted documents the editor encrypts staged objects to match; random feeds the per-object IVs (seed it for reproducible output in tests).
Look up a form field by its fully-qualified name; null if not present.
Resolve a /Dest (on a Link annotation or outline) or /A /D (a GoTo action's destination) to a typed PdfDestination. Accepts any of: an explicit array, a name pointing into the catalog's name-tree, or a dict containing /D (a wrapped destination). Returns null when the destination can't be resolved.
Find needle across the whole document, page by page. The result is a lazy Sequence, so a UI can surface incremental hits while later pages are still being extracted. See PdfPage.search for matching rules.