Group a range of text fragments into a set of lines.




IList<TextGroup> Group(List<TextFragment> fragments)
[Visual Basic]
Function Group(fragments As List<TextFragment>) As IList<TextGroup>



Name Description
fragments The fragments to be grouped.
Return Returns a list of groups defining the words.




Group a range of text fragments into a set of lines.

Calling Select will return a list of TextFragments corresponding to the section of text you are interested in. However each TextFragment may only make up a small portion of a word. Calling this function allows you to group connected fragments into continuous sections with a common rectangular area.

Strictly speaking this grouping does not always correspond to lines. For example two fragments on the same line, separated by a large distance, will not be considered contiguous. However for most purposes the two broadly correspond.




Here we highlight a set of words in a source document by drawing a rectangle around each one.

string theSrc = Server.MapPath("Acrobat.pdf");
string theDst = Server.MapPath("HighlightedText.pdf");
string searchString = "Acrobat";
using (Doc theDoc = new Doc()) {
  TextOperation op = new TextOperation(theDoc);
  string text = op.GetText();
  int pos = 0;
  while (true) {
    pos = text.IndexOf(searchString, pos, StringComparison.CurrentCultureIgnoreCase);
    if (pos < 0)
    IList<TextFragment> theSelection = op.Select(pos, searchString.Length);
    IList<TextGroup> theGroups = op.Group(theSelection);
    foreach (TextGroup theGroup in theGroups) {
      theDoc.Rect.String = theGroup.Rect.String;
    pos += searchString.Length;

[Visual Basic]
Dim theSrc As String = Server.MapPath("Acrobat.pdf")
Dim theDst As String = Server.MapPath("HighlightedText.pdf")
Dim searchString As String = "Acrobat"
Using theDoc As New Doc()
  Dim op As New TextOperation(theDoc)
  Dim text As String = op.GetText()
  Dim pos As Integer = 0
  While True
    pos = text.IndexOf(searchString, pos, StringComparison.CurrentCultureIgnoreCase)
    If pos < 0 Then
      Exit While
    End If
    Dim theSelection As IList(Of TextFragment) = op.[Select](pos, searchString.Length)
    Dim theGroups As IList(Of TextGroup) = op.Group(theSelection)
    For Each theGroup As TextGroup In theGroups
      theDoc.Rect.[String] = theGroup.Rect.[String]
    pos += searchString.Length
  End While
End Using