Skip to content
ComPDF
DemoFAQ
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

Cancel Conversion Task

ComPDF Conversion SDK supports interrupting your ongoing conversion task at any time. The following example demonstrates how to interrupt your ongoing conversion task.

kotlin
// Implement the `ConvertCallback` interface to receive conversion progress updates, and to control cancellation of the conversion task.
class ConversionTask(
    var path: String,
    var outputPath: String,
    var options: WordOptions
) : ConvertCallback {

    override fun onProgress(current: Int, total: Int) {
        println("progress: $current / $total")
    }

    // When the conversion task is running, set `cancelled` to true to interrupt the ongoing conversion task.
    @Volatile
    var cancelled: Boolean = false

    override fun isCancelled() {
        return cancelled
    }

    fun startTask() {
        val errorCode = ComPDFKitConverter.startPDFToWord(path, "", outputPath, options, this)
    }
}