Skip to main content

File Import

You can import images or PDF files into Docutain and do a bunch of things with them, same as after a successful document scan with Docutain's Kotlin Multiplatform Scanner SDK.

Kotlin Multiplatform PDF Creation

Kotlin Multiplatform Text Recognition

Kotlin Multiplatform Data Extraction

Supported file types​

The native Docutain data reader supports PDF, BMP, JPG, JPEG, PNG, TIFF and HEIC files.

Use DocutainSdk.loadFile to import files for text recognition, data extraction and subsequent exports.

Initialization​

  • Follow the Getting started guide
  • Initialize the Docutain SDK for Kotlin Multiplatform as described here

File Import​

If you want to import a PDF file, create a searchable PDF, or get the detected data or text of the imported file, use DocutainSdk.loadFile.

import de.docutain.sdk.kmp.DocutainException
import de.docutain.sdk.kmp.DocutainSdk

val scope = rememberCoroutineScope()
scope.launch {
try {
DocutainSdk.loadFile(filePath)

// generate a PDF from the imported file
val pdfFile = DocutainSdk.writePDF()

// get the detected text
val text = DocutainSdk.getText()

// get the detected data
val data = DocutainSdk.analyze()
} catch (exception: DocutainException) {
// the file could not be loaded or processed
val message = exception.message
}
}

loadFile is a suspend function. See Coroutines and suspend functions for more details.

The supplied value can be an absolute file path or a file:// URL. The file must be readable by the app.

Encrypted PDF files​

If the PDF is encrypted, pass its password to loadFile. A missing or wrong password, or an unreadable file, causes DocutainException:

val scope = rememberCoroutineScope()
scope.launch {
try {
DocutainSdk.loadFile(filePath, password = password)
// Work with the imported PDF.
} catch (exception: DocutainException) {
// Check the error before telling the user the password was wrong.
val message = exception.message
}
}