Skip to content
DemoFAQ

PDF 生成模板编辑器

开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。

查看 GitHub

取消转换任务

ComPDF Conversion SDK 支持随时中断您正在进行的转档任务,以下示例演示了如何中断您正在进行的转档任务。

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 = ComPDFConverter.startPDFToWord(path, "", outputPath, options, this)
    }
}