Class PdfVectorTextService
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
documentIPdfDocumentvectorDocumentPdfVectorDocument
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
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.
public 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.
public 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.