save

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.

Example:

val saved = pdf {
page { text("Hi") }
}.save(StorageLocation.Downloads, "hello.pdf")

println("Saved to ${saved.path}")

For StorageLocation.Custom with a full file path the filename argument may be omitted — the library writes the bytes directly to the supplied path:

document.save(StorageLocation.Custom("/storage/.../picked.pdf"))

Return

SavedPdf containing the absolute path and optional content URI.

Parameters

location

target directory; see StorageLocation for per-platform semantics.

filename

file name including the extension; required for every variant except StorageLocation.Custom when the path already includes the file name.