Class TextFragmentAbsorber

TextFragmentAbsorber class

Represents an absorber object of text fragments. Performs text search and provides access to search results via TextFragments collection.

public sealed class TextFragmentAbsorber : TextAbsorber

Constructors

NameDescription
TextFragmentAbsorber()Initializes a new instance of the TextFragmentAbsorber that performs search of all text segments of the document or page.
TextFragmentAbsorber(Regex)Initializes a new instance of the TextFragmentAbsorber class for the specified System.Text.RegularExpressions.Regex class object.
TextFragmentAbsorber(string)Initializes a new instance of the TextFragmentAbsorber class for the specified text phrase.
TextFragmentAbsorber(TextEditOptions)Initializes a new instance of the TextFragmentAbsorber with text edit options, that performs search of all text segments of the document or page.
TextFragmentAbsorber(Regex, TextEditOptions)Initializes a new instance of the TextFragmentAbsorber class for the specified text phrase and text edit options.
TextFragmentAbsorber(Regex, TextSearchOptions)Initializes a new instance of the TextFragmentAbsorber class for the specified text phrase and text search options.
TextFragmentAbsorber(Regex[], TextSearchOptions)Initializes a new instance of the TextFragmentAbsorber class for the specified text phrase and text search options.
TextFragmentAbsorber(string, TextEditOptions)Initializes a new instance of the TextFragmentAbsorber class for the specified text phrase and text edit options.
TextFragmentAbsorber(string, TextSearchOptions)Initializes a new instance of the TextFragmentAbsorber class for the specified text phrase and text search options.
TextFragmentAbsorber(string, TextSearchOptions, TextEditOptions)Initializes a new instance of the TextFragmentAbsorber class for the specified text phrase, text search options and text edit options.

Properties

NameDescription
Errors { get; }List of TextExtractionError objects. It contain information about errors were found during text extraction. Searching for errors will performed only if TextSearchOptions.LogTextExtractionErrors = true; And it may decrease performance.
override ExtractionOptions { get; set; }Gets or sets text extraction options.
HasErrors { get; }Value indicates whether errors were found during text extraction. Searching for errors will performed only if TextSearchOptions.LogTextExtractionErrors = true; And it may decrease performance.
Phrase { get; set; }Gets or sets phrase that the TextFragmentAbsorber searches on the PDF document or page.
RegexResults { get; }Gets dictionary of search occurrences that are presented with System.Text.RegularExpressions.Regex class as key and TextFragment as value.
override Text { get; }Gets extracted text that the TextAbsorber extracts on the PDF document or page.
TextEditOptions { get; set; }Gets or sets text edit options. The options define special behavior when requested symbol cannot be written with font.
TextFragments { get; set; }Gets collection of search occurrences that are presented with TextFragment objects.
TextReplaceOptions { get; set; }Gets or sets text replace options. The options define behavior when fragment text is replaced to more short/long.
TextSearchOptions { get; set; }Gets or sets search options. The options enable search using regular expressions.

Methods

NameDescription
ApplyForAllFragments(float)Applies font size for all text fragments that were absorbed. It works faster than looping through the fragments if all fragments on the page(s) were absorbed. Otherwise it works similar with looping.
ApplyForAllFragments(Font)Applies font for all text fragments that were absorbed. It works faster than looping through the fragments if all fragments on the page(s) were absorbed. Otherwise it works similar with looping.
ApplyForAllFragments(Font, float)Applies font and size for all text fragments that were absorbed. It works faster than looping through the fragments if all fragments on the page(s) were absorbed. Otherwise it works similar with looping.
RemoveAllText(Document)Removes all text from the document.
RemoveAllText(Page)Removes all text from the specified page.
RemoveAllText(Page, Rectangle)Removes text inside the specified rectangle from the specified page.
Reset()Clears TextFragments collection of this TextFragmentAbsorber object.
override Visit(Document)Performs search on the specified document.
override Visit(Page)Performs search on the specified page.
Visit(XForm)Performs search on the specified form object.
virtual Visit(XForm)Extracts text on the specified XForm.

Remarks

The TextFragmentAbsorber object is basically used in text search scenario. When the search is completed the occurrences are represented with TextFragment objects that the TextFragments collection contains. The TextFragment object provides access to the search occurrence text, text properties, and allows to edit text and change the text state (font, font size, color etc).

Examples

The example demonstrates how to find text on the first PDF document page and replace the text and it’s font.

// Open document
Document doc = new Document(@"D:\Tests\input.pdf");

// Find font that will be used to change document text font
Aspose.Pdf.Txt.Font font = FontRepository.FindFont("Arial");

// Create TextFragmentAbsorber object to find all "hello world" text occurrences
TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world");

// Accept the absorber for first page
doc.Pages[1].Accept(absorber);

// Change text and font of the first text occurrence
absorber.TextFragments[1].Text = "hi world";
absorber.TextFragments[1].TextState.Font = font;

// Save document
doc.Save(@"D:\Tests\output.pdf");  

See Also