Show / Hide Table of Contents

# Class TextRange

The `TextRange` class represents a contiguous range of text on a PDF page. It may be the result of a text search, or simply a couple of highlighted or underlined words.

Each text range contains a few pieces of information:

page: the number of the page this piece of text is on; position: the start position (text offset); length: the length.

You are able to retrieve further information about the text range, such as its coordinates, the text itself, as well as characters before and after.

##### Inheritance

object
TextRange

##### Implements

IDisposable

##### Inherited Members

object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()

###### Namespace: pdftron.PDF

###### Assembly: PDFTronDotNet.dll

##### Syntax

    public class TextRange : IDisposable

### Constructors

#### TextRange()

Creates a default `TextRange` object

##### Declaration

    public TextRange()

#### TextRange(TextRange)

Creates a TextRange from a given object

##### Declaration

    public TextRange(TextRange tr)

##### Parameters

Type | Name | Description
--- | --- | ---
TextRange | tr | a given `TextRange` object

### Methods

#### Destroy()

##### Declaration

    public void Destroy()

#### Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

##### Declaration

    public void Dispose()

#### Dispose(bool)

##### Declaration

    protected virtual void Dispose(bool disposing)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | disposing |

#### ~TextRange()

Releases all resources used by the TextRange

##### Declaration

    protected ~TextRange()

#### GetPageNumber()

Get the page number of the text range.

##### Declaration

    public int GetPageNumber()

##### Returns

Type | Description
--- | ---
int | the page number

#### GetQuads()

Get the corresponding quadrangles of the text range.

##### Declaration

    public double[] GetQuads()

##### Returns

Type | Description
--- | ---
double[] | the output quadrangles. Each quadrangle has eight doubles (x1, y1), (x2, y2), (x3, y3), (x4, y4) denoting the four vertices in counter-clockwise order.

##### Remarks

since a highlight may correspond to multiple quadrangles, e.g., when it crosses a line, the number of resulting quadrangles may be larger than 1.

#### GetText()

Get the Unicode string content of the text range.

##### Declaration

    public string GetText()

##### Returns

Type | Description
--- | ---
string | the text within the range

#### GetTextAfter(int)

Get the Unicode string content immediately after the text range.

##### Declaration

    public string GetTextAfter(int count)

##### Parameters

Type | Name | Description
--- | --- | ---
int | count | the number of characters to retrieve after the text range

##### Returns

Type | Description
--- | ---
string | the text after the range

#### GetTextBefore(int)

Get the Unicode string content immediately before the text range.

##### Declaration

    public string GetTextBefore(int count)

##### Parameters

Type | Name | Description
--- | --- | ---
int | count | the number of characters to retrieve before the text range

##### Returns

Type | Description
--- | ---
string | the text before the range

### Implements

IDisposable