Table of Contents

Class PdfVectorTextService

Namespace
PdfEngine.Vector.Text
Assembly
PdfEngine.Vector.dll

The native IPdfTextService: word segments, page text and search from PdfTextPage, with the same results (and the same normalized-coordinate and padding conventions) as the PDFium text service it replaces. It works on a PdfVectorDocument; a document opened by another engine is read through a vector document attached to it (Attach(IPdfDocument, PdfVectorDocument)) or, failing that, opened from its file.

public sealed class PdfVectorTextService : IPdfTextService
Inheritance
PdfVectorTextService
Implements
Inherited Members

Methods

Attach(IPdfDocument, PdfVectorDocument)

Reads document's text from vectorDocument (the same file, opened by the vector engine).

public void Attach(IPdfDocument document, PdfVectorDocument vectorDocument)

Parameters

document IPdfDocument
vectorDocument PdfVectorDocument

ExtractPageTextAsync(IPdfDocument, int, CancellationToken)

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

public 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.

public 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.

public 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.