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

Namespace: Aspose.Pdf.Text
Assembly: Aspose.PDF (in Aspose.PDF.dll) Version: 18.6
Syntax
public sealed class TextFragmentAbsorber : TextAbsorber

The TextFragmentAbsorber type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleTextFragmentAbsorber
Initializes a new instance of the TextFragmentAbsorber that performs search of all text segments of the document or page.
Public methodCode exampleTextFragmentAbsorber(String)
Initializes a new instance of the TextFragmentAbsorber class for the specified text phrase.
Public methodCode exampleTextFragmentAbsorber(TextEditOptions)
Initializes a new instance of the TextFragmentAbsorber with text edit options, that performs search of all text segments of the document or page.
Public methodTextFragmentAbsorber(String, TextEditOptions)
Initializes a new instance of the TextFragmentAbsorber class for the specified text phrase and text edit options.
Public methodCode exampleTextFragmentAbsorber(String, TextSearchOptions)
Initializes a new instance of the TextFragmentAbsorber class for the specified text phrase and text search options.
Public methodCode exampleTextFragmentAbsorber(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
Public propertyErrors
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.
Public propertyExtractionOptions
Gets or sets text extraction options.
(Overrides TextAbsorberExtractionOptions.)
Public propertyHasErrors
Value indicates whether errors were found during text extraction. Searching for errors will performed only if TextSearchOptions.LogTextExtractionErrors = true; And it may decrease performance.
Public propertyCode examplePhrase
Gets or sets phrase that the TextFragmentAbsorber searches on the PDF document or page.
Public propertyText
Gets extracted text that the TextAbsorber extracts on the PDF document or page.
(Overrides TextAbsorberText.)
Public propertyTextEditOptions
Gets or sets text edit options. The options define special behavior when requested symbol cannot be written with font.
Public propertyCode exampleTextFragments
Gets collection of search occurrences that are presented with TextFragment objects.
Public propertyTextReplaceOptions
Gets or sets text replace options. The options define behavior when text fragment is replaced to more short.
Public propertyCode exampleTextSearchOptions
Gets or sets search options. The options enable search using regular expressions.
Methods
  NameDescription
Public methodApplyForAllFragments(Single)
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.
Public methodApplyForAllFragments(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.
Public methodApplyForAllFragments(Font, Single)
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.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Public methodReset
Clears TextFragments collection of this TextFragmentAbsorber object.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodCode exampleVisit(Document)
Performs search on the specified document.
(Overrides TextAbsorberVisit(Document).)
Public methodCode exampleVisit(Page)
Performs search on the specified page.
(Overrides TextAbsorberVisit(Page).)
Public methodVisit(XForm)
Performs search on the specified form object.
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.
C#
// 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