Coroutines and suspend functions
Operations that open a user interface or perform file, recognition, or export work are exposed as Kotlin suspend functions. Call them from a coroutine:
import androidx.compose.runtime.rememberCoroutineScope
import kotlinx.coroutines.launch
val scope = rememberCoroutineScope()
Button(onClick = {
scope.launch {
try {
val completed = DocutainSdk.scanDocument()
// Handle the result.
} catch (exception: DocutainException) {
// Handle the error.
}
}
}) {
Text("Scan document")
}
The KMP SDK handles the native thread dispatching required by its blocking operations. Do not use runBlocking on the UI thread.
The following common API methods suspend:
scanDocumentloadFilegetTextandgetTextPagesetAnalyzeConfigurationandanalyzewritePDF,writeImage, andgetImageBytesstartPhotoPaymentandstartPhotoPaymentWithExternalFiles