PdfDocument

A fully-rendered PDF document, ready to be persisted or transferred.

Instances are immutable and safe to share across threads. The encoded bytes are produced once during pdf and reused for every accessor call — toByteArray returns a defensive copy so the caller cannot mutate the library-internal buffer.

kotlinx-io is used for file I/O so save works the same way on Android, iOS, and any future Kotlin/JVM, Kotlin/Native, or Kotlin/JS target without platform-specific code.

Properties

Link copied to clipboard

Every hyperlink annotation captured during rendering. Powers :pdfkmp-viewer's clickable-link overlay — see PdfHyperlink for the coordinate system. Empty for documents that were rendered before the recording infrastructure existed.

Link copied to clipboard
val size: Int

Total size of the encoded document in bytes.

Link copied to clipboard

Every laid-out text run captured during rendering, in draw order. Powers :pdfkmp-viewer's text selection overlay — see PdfTextRun for the coordinate system. Empty for documents that were rendered before the recording infrastructure existed (e.g. tests that build a PdfDocument manually).

Functions

Link copied to clipboard
fun save(path: String)

Writes the encoded PDF to the file at path, creating any missing parent directories.

Link copied to clipboard
fun PdfDocument.save(location: StorageLocation, filename: String = ""): SavedPdf

Saves this document to the platform-specific location under filename. Returns the absolute path and (on Android Q+ public writes) the content URI of the persisted file.

Link copied to clipboard

Returns a fresh copy of the encoded PDF bytes.