Skip to content
DemoFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

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)
    }
}