Progressive Rendering and Cancellation

HotPDF can render a loaded page over multiple bounded calls and can stop long-running document operations through a shared caller-owned cancellation token

Progressive page rendering

Session := PDF.BeginLoadedPageProgressiveRender(0, 144);
try
  repeat
    Status := Session.ContinueRender(8, 128);
    Preview.Assign(Session.Bitmap);
  until Status in [prsCompleted, prsCancelled];

  if Status = prsCompleted then
    FinalBitmap := Session.TakeBitmap;
finally
  Session.Free;
end;

ContinueRender accepts a maximum elapsed time in milliseconds, a maximum number of top-level page content operators, or both; zero means unlimited for that budget

The call completes at least one operator before applying a non-zero time budget, so the graphics state is always paused at an operator boundary

Bitmap exposes the live caller-read-only partial bitmap, while TakeBitmap transfers ownership without copying after the session reaches prsCompleted or prsCancelled

ObjectsProcessed and TotalObjects report top-level content operators from every page /Contents stream in source order

Progress callbacks

THPDFProgressiveRenderProgressEvent runs after each completed operator and receives processed and total counts plus elapsed render-execution time

Set the callback Cancel parameter to true to finish that session in prsCancelled without cancelling the shared token

A Form XObject, pattern, image decode, or other nested operation belongs to its enclosing top-level operator and may exceed a small time budget before control returns

Operation-wide cancellation

Token := THPDFCancellationToken.Create;
try
  PDF.OperationCancellationToken := Token;
  Worker.Start;
  // Call Token.Cancel from another thread when the operation should stop
finally
  PDF.OperationCancellationToken := nil;
  Token.Free;
end;

THPDFCancellationToken is thread-safe, one-shot, and owned by the caller; Cancel permanently requests cancellation and IsCancellationRequested exposes the state

ThrowIfCancellationRequested raises EHPDFOperationCancelled and preserves the operation name in OperationName

THotPDF.OperationCancellationToken applies to load, synchronous render, progressive render without an explicit token, OptimizeLoadedStreams, CreatePreflightReport, and ValidatePDFVT

SignPDFWithPFX and SignPDFWithSystemCertificate provide overloads that accept a token directly

Ownership and partial-result rules

Related APIs