Interface IPdfTextService
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
documentIPdfDocumentAn open document.
pageNumberintThe page number, starting at 1.
cancellationTokenCancellationTokenCancels the operation.
Returns
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
documentIPdfDocumentAn open document.
pageNumberintThe page number, starting at 1.
cancellationTokenCancellationTokenCancels 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
documentIPdfDocumentAn open document.
querystringThe text to find. An empty query finds nothing.
optionsSearchOptionsCase, whole-word and result-count options; null uses the defaults.
cancellationTokenCancellationTokenCancels the search.
Returns
- ValueTask<IReadOnlyList<SearchMatch>>
The matches in page order, at most MaxResults.