Skip to main content

Module async_api

Module async_api 

Source
Available on crate feature async only.
Expand description

Executor-agnostic async wrappers for PDFKit document finding.

Enabled with the async Cargo feature.

PdfDocumentFindStream runs PDFDocument.findString(_:withOptions:) on a worker thread, converts every match into an owned Rust snapshot, and emits a bounded async stream backed by doom_fish_utils::stream::BoundedAsyncStream.

The stream emits synthetic DidBeginFind / DidEndFind notifications around the match sequence. Dropping it waits for the worker thread to finish and then closes the stream.

§Example

use pdfkit::async_api::{
    PdfDocumentFindEvent, PdfDocumentFindOptions, PdfDocumentFindStream,
};
use pdfkit::PdfDocument;

let document = PdfDocument::from_url("examples/assets/hello.pdf")?;
let stream = PdfDocumentFindStream::find_string(
    &document,
    "Hello",
    PdfDocumentFindOptions::NONE,
    8,
)?;

while let Some(event) = stream.next().await {
    match event {
        PdfDocumentFindEvent::Notification(notification) => {
            println!("notification={}", notification.name());
        }
        PdfDocumentFindEvent::Match(found) => {
            println!("match={:?} pages={:?}", found.text, found.pages);
        }
        PdfDocumentFindEvent::Failed(error) => {
            eprintln!("search failed: {error}");
        }
    }
}

Structs§

PdfDocumentFindMatch
Owned snapshot of one PDFDocument string match.
PdfDocumentFindOptions
PDFDocument.findString(_:withOptions:) comparison options.
PdfDocumentFindPageMatch
One page of a match snapshot emitted by PdfDocumentFindStream.
PdfDocumentFindStream
Async stream of PDFDocument find notifications and match snapshots.

Enums§

PdfDocumentFindEvent
Events emitted while a PDFKit string search is running.