useNativeDocumentHandle<T> abstract method

Future<T> useNativeDocumentHandle<T>(
  1. FutureOr<T> task(
    1. int nativeDocumentHandle
    )
)

Execute native document task with the native document handle.

Only supported for native backends (e.g., PDFium).

Please note that this function suspends pdfrx internal PDFium worker during the execution of task. Do not await worker operations or disposal of this document inside task, and do not retain the handle after task completes. The native PDFium backend keeps the document alive until task completes.

If you modify the document inside task, make sure to keep consistency of the document after the modification; e.g., call reloadPages if necessary.

nativeDocumentHandle is a pointer to the native PDF document handle (e.g., FPDF_DOCUMENT in PDFium) but represented as an integer to avoid direct dependency to PDFium bindings.

final result = await pdfDocument.useNativeDocumentHandle((nativeDocumentHandle) {
  // Convert nativeDocumentHandle to FPDF_DOCUMENT handle.
  final pdfDocument = pdfium_bindings.FPDF_DOCUMENT.fromAddress(nativeDocumentHandle);
  // <<Do something with pdfDocument...>>
  return someResult;
});

Implementation

Future<T> useNativeDocumentHandle<T>(FutureOr<T> Function(int nativeDocumentHandle) task);