open

fun KiteDoc.open(context: Context, uri: Uri, password: String = "", epubSettings: EpubSettings = EpubSettings()): KiteDocument

Opens a content uri, which is what the system file picker (ACTION_OPEN_DOCUMENT) and share intents actually hand you. A content:// Uri has no file path, so this reads it through Context.getContentResolver.

val pick = registerForActivityResult(OpenDocument()) { uri ->
uri ?: return@registerForActivityResult
val doc = KiteDoc.open(this, uri)
}
pick.launch(arrayOf("application/pdf", "application/epub+zip"))

Reads the whole document into memory, so keep it off the main thread for anything large.

Throws

when the Uri cannot be opened, or is neither a PDF nor an EPUB.

fun KiteDoc.open(url: NSURL, password: String = "", epubSettings: EpubSettings = EpubSettings()): KiteDocument

Opens an NSURL. A file URL is read straight off disk; anything else is left to Foundation, so a file:// bookmark from UIDocumentPickerViewController works, and a remote URL blocks the calling thread. For remote documents prefer the kitepdf-net artifact, which fetches asynchronously.

Throws

when the URL cannot be read, or is neither format.


fun KiteDoc.open(data: NSData, password: String = "", epubSettings: EpubSettings = EpubSettings()): KiteDocument

Opens data you already hold, e.g. from a network call or the pasteboard.