public class

TextRange

extends Object
implements AutoCloseable
java.lang.Object
   ↳ com.pdftron.pdf.TextRange

Class Overview

The TextRange is used to store the necessary information and perform certain 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.

Summary

Public Constructors
TextRange()
Instantiate default text range.
Public Methods
void close()
Frees the native memory of the object.
void destroy()
Frees the native memory of the object.
int getPageNumber()
Get the page number of the text range.
double[] getQuads()
Get the corresponding quadrangles of the text range.
String getText()
Get the Unicode string content of the text range.
String getTextAfter(int count)
Get the Unicode string content immediately after the text range.
String getTextBefore(int count)
Get the Unicode string content immediately before the text range.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.AutoCloseable

Public Constructors

public TextRange ()

Instantiate default text range.

Public Methods

public void close ()

Frees the native memory of the object. This can be explicity called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

public void destroy ()

Frees the native memory of the object. This can be explicity called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

public int getPageNumber ()

Get the page number of the text range.

Returns
  • the page number

public double[] getQuads ()

Get the corresponding quadrangles of the text range.

Note: 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.

Returns
  • the output quadrangles. Each quadrangle has eight doubles (x1, y1), (x2, y2), (x3, y3), (x4, y4) denoting the four vertices in counter-clockwise order.

public String getText ()

Get the Unicode string content of the text range.

Returns
  • the text within the range.

public String getTextAfter (int count)

Get the Unicode string content immediately after the text range.

Parameters
count the number of characters to retrieve after the text range.
Returns
  • the text after the range.

public String getTextBefore (int count)

Get the Unicode string content immediately before the text range.

Parameters
count the number of characters to retrieve before the text range.
Returns
  • the text before the range.