Table of Contents

Interface IPdfTextService

Namespace
PdfEngine.Text
Assembly
PdfEngine.Abstractions.dll

Text extraction and text search contract.

public interface IPdfTextService

Methods

ExtractPageTextAsync(IPdfDocument, int, CancellationToken)

Gets the text of a page as one string, in the page's character order.

ValueTask<string> ExtractPageTextAsync(IPdfDocument document, int pageNumber, CancellationToken cancellationToken = default)

Parameters

document IPdfDocument

An open document.

pageNumber int

The page number, starting at 1.

cancellationToken CancellationToken

Cancels the operation.

Returns

ValueTask<string>

The text; an empty string for a page without text or a page number out of range.

ExtractTextSegmentsAsync(IPdfDocument, int, CancellationToken)

Gets the words of a page with their positions.

ValueTask<IReadOnlyList<TextSegment>> ExtractTextSegmentsAsync(IPdfDocument document, int pageNumber, CancellationToken cancellationToken = default)

Parameters

document IPdfDocument

An open document.

pageNumber int

The page number, starting at 1.

cancellationToken CancellationToken

Cancels the operation.

Returns

ValueTask<IReadOnlyList<TextSegment>>

The segments in the page's character order; an empty list for a page without text or a page number out of range.

SearchTextAsync(IPdfDocument, string, SearchOptions?, CancellationToken)

Finds every occurrence of query in the document, page by page.

ValueTask<IReadOnlyList<SearchMatch>> SearchTextAsync(IPdfDocument document, string query, SearchOptions? options = null, CancellationToken cancellationToken = default)

Parameters

document IPdfDocument

An open document.

query string

The text to find. An empty query finds nothing.

options SearchOptions

Case, whole-word and result-count options; null uses the defaults.

cancellationToken CancellationToken

Cancels the search.

Returns

ValueTask<IReadOnlyList<SearchMatch>>

The matches in page order, at most MaxResults.