Cancel Conversion Task
Assign a callable to $onCancel on the ConvertCallback to abort a long-running task. The SDK polls the callback periodically; returning true causes the conversion to stop and the corresponding Conversion::pdfTo*() call to return ErrorCode::CANCEL (value 1).
php
use ComPDFKit\Conversion\Conversion;
use ComPDFKit\Conversion\ConvertCallback;
use ComPDFKit\Conversion\ConvertOption;
use ComPDFKit\Conversion\ErrorCode;
$cb = new ConvertCallback();
$pagesDone = 0;
$cb->onProgress = static function (int $current, int $total) use (&$pagesDone): void {
$pagesDone = $current;
};
$cb->onCancel = static function () use (&$pagesDone): bool {
return $pagesDone >= 1; // stop after the first page
};
$option = new ConvertOption();
$code = Conversion::pdfToWord('input.pdf', '', 'output.docx', $option, $cb);
echo ErrorCode::describe($code) . PHP_EOL; // "Cancel"