# Text Class

> A container that represents a series of text elements and characters.

- Product: Adobe PDF Library 18
- Language: Java
- Version: APDFL18.0.5PlusP2e
- HTML page: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Text
- Version index: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/llms.txt

```java
class Text : Element
```

**Namespace:** `com::datalogics::PDFL`

**Inherits from:** [`Element`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Element.md)

## Description

A container that represents a series of text elements and characters. A Text object is container that represents both a series of TextRun elements and a series of text characters. Operations can be performed on individual TextRuns within a Text or on individual characters within a Text by specifying the index of the individual TextRun or character. All indices start at 0.

**Referenced by:** [`Text`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Text.md)

**Uses types:** [`Clip`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Clip.md), [`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md), [`Font`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Font.md), [`GraphicState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/GraphicState.md), [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md), [`Point`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Point.md), [`Rect`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Rect.md), [`Text`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Text.md), [`TextRun`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/TextRun.md), [`TextState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/TextState.md)

## Constructors

### Text

```java
com.datalogics.PDFL.Text.Text()
```

*constructor*

Create a new, empty Text object.

## Methods

### addGlyphs

```java
void com.datalogics.PDFL.Text.addGlyphs(java.util.List< java.lang.Character > glyphIDs, java.util.List< java.lang.Character > uniText, Font font, GraphicState gState, TextState state, Matrix matrix, java.util.EnumSet< TextFlags > flags)
```

**Parameters**

- `glyphIDs` (`java.util.List< java.lang.Character >`): Glyphs IDs in the specified font for adding to the page's content
- `uniText` (`java.util.List< java.lang.Character >`): Unicode codes for the specified glyph IDs
- `font` ([`Font`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Font.md)): Font for wich GlyphIDs were specified
- `gState` ([`GraphicState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/GraphicState.md)): The GraphicsState for Text element
- `state` ([`TextState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/TextState.md)): TextState flags
- `matrix` ([`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)): matrix for the Text element
- `flags` (`java.util.EnumSet< TextFlags >`): TextFlags that specifies what kind of text to add

**Returns:** `void`

Adds Unicode text to a Text object

### addGlyphs

```java
void com.datalogics.PDFL.Text.addGlyphs(java.util.List< java.lang.Character > glyphIDs, java.util.List< java.lang.Character > uniText, Font font, GraphicState gState, TextState state, Matrix matrix, java.util.EnumSet< TextFlags > flags, int index)
```

**Parameters**

- `glyphIDs` (`java.util.List< java.lang.Character >`): Glyphs IDs in the specified font to add to the page's content
- `uniText` (`java.util.List< java.lang.Character >`): Unicode codes for the specified glyph IDs
- `font` ([`Font`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Font.md)): Font for wich GlyphIDs were specified
- `gState` ([`GraphicState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/GraphicState.md)): The GraphicsState for Text element
- `state` ([`TextState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/TextState.md)): TextState flags
- `matrix` ([`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)): matrix for the Text element
- `flags` (`java.util.EnumSet< TextFlags >`): TextFlags that specifies what kind of text to add
- `index` (`int`): The index after which to add the character or text run.

**Returns:** `void`

Adds Unicode text to a Text object

### addRun

```java
void com.datalogics.PDFL.Text.addRun(TextRun run)
```

**Parameters**

- `run` ([`TextRun`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/TextRun.md)): The TextRun to append.

**Returns:** `void`

Adds a TextRun to the end of this text element.

### addRun

```java
void com.datalogics.PDFL.Text.addRun(TextRun run, int index)
```

**Parameters**

- `run` ([`TextRun`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/TextRun.md)): TextRun to be added
- `index` (`int`): Index, where TextRun should be placed

**Returns:** `void`

Adds a TextRun at the specified index.

### changeMatrixForTextRun

```java
void com.datalogics.PDFL.Text.changeMatrixForTextRun(Matrix newMatrix, int textRunIndex)
```

**Parameters**

- `newMatrix` ([`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)): The new transformation matrix to use for the TextRun.
- `textRunIndex` (`int`): The index of a TextRun, relative to the Text object (the first TextRun in the Text object is at index 0).

**Returns:** `void`

Changes the transformation matrix from user space to the current text space for the specified TextRun. Unlike ChangeTextMatrixForTextRun(), this function does not change fontSize, hScale, and textRise in the textState of PDEText. The H and V values of the matrix indicate the origin of the first character.

### changeTextMatrixForTextRun

```java
void com.datalogics.PDFL.Text.changeTextMatrixForTextRun(Matrix newMatrix, int textRunIndex)
```

**Parameters**

- `newMatrix` ([`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)): The new transformation matrix to use for the TextRun.
- `textRunIndex` (`int`): The index of a TextRun, relative to the Text object (the first TextRun in the Text object is at index 0).

**Returns:** `void`

Changes the transformation matrix from user space to the current text space for the specified TextRun. The H and V values of the matrix indicate the origin of the first character.

### clone

```java
Text com.datalogics.PDFL.Text.clone()
```

**Returns:** [`Text`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Text.md)

The copied text.

Makes a copy of the text.

Make a copy of an text to obtain a new text that has a distinct set of attributes.

### clone

```java
Text com.datalogics.PDFL.Text.clone(java.util.EnumSet< ElementCloneFlags > cloneFlags)
```

**Parameters**

- `cloneFlags` (`java.util.EnumSet< ElementCloneFlags >`): Flags that modify the cloning operation.

**Returns:** [`Text`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Text.md)

The copied text.

Makes a copy of the text.

Make a copy of an text to obtain a new text that has a distinct set of attributes.

### colorConvert

```java
Text com.datalogics.PDFL.Text.colorConvert(Document document, ColorProfile prof, RenderIntent intent, boolean embed)
```

**Parameters**

- `document` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md)): The document the element belongs to.
- `prof` (`ColorProfile`): The ICC ColorProfile to be applied.
- `intent` (`RenderIntent`): The ICC Rendering Intent for the ColorProfile
- `embed` (`boolean`): If true, embed the color space and make the object calibrated. If it is false and the target profile is CMYK, RGB, or Gray, the colors space of the resulting object, after conversion, will be DeviceCMYK, DeviceRGB, or DeviceGray, respectively.

**Returns:** [`Text`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Text.md)

A new Text object with the applied ICC ColorProfile.

Applies the specified ICC ColorProfile to the Text object

### delete

```java
synchronized void com.datalogics.PDFL.Text.delete(Boolean disposing)
```

*protected*

**Parameters**

- `disposing` (`Boolean`)

**Returns:** `synchronized void`

### delete

```java
synchronized void com.datalogics.PDFL.Text.delete()
```

**Returns:** `synchronized void`

### finalize

```java
void com.datalogics.PDFL.Text.finalize()
```

*protected*

**Returns:** `void`

### findTextRunIndexForCharacter

```java
int com.datalogics.PDFL.Text.findTextRunIndexForCharacter(int characterIndex)
```

**Parameters**

- `characterIndex` (`int`): The index of a character, relative to the Text object (the first character in the Text object is at index 0).

**Returns:** `int`

The index of the TextRun that contains the character specified by characterIndex.

Finds the index of the TextRun that contains the nth character in a Text object.

### getAdvanceForCharacter

```java
Point com.datalogics.PDFL.Text.getAdvanceForCharacter(int characterIndex)
```

**Parameters**

- `characterIndex` (`int`): The index of a character, relative to the Text object (the first character in the Text object is at index 0).

**Returns:** [`Point`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Point.md)

A value specifying both the horizontal and vertical components of the advance width of a character in user space.

Gets the advance width of a character, in user space. The advance width is the amount by which the current point advances when the character is drawn.

Advance width may be horizontal or vertical, depending on the writing style. Thus, the return value has both a horizontal and a vertical component.

### getAdvanceForTextRun

```java
Point com.datalogics.PDFL.Text.getAdvanceForTextRun(int textRunIndex)
```

**Parameters**

- `textRunIndex` (`int`): The index of a TextRun, relative to the Text object (the first TextRun in the Text object is at index 0).

**Returns:** [`Point`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Point.md)

A value specifying both the horizontal and vertical components of the advance width of a TextRun in user space.

Gets the advance width of a TextRun, in user space. The advance width is the amount by which the current point advances when the TextRun is drawn.

Advance width may be horizontal or vertical, depending on the writing style. Thus, the return value has both a horizontal and a vertical component.

### getBoundingBox

```java
Rect com.datalogics.PDFL.Element.getBoundingBox()
```

**Returns:** [`Rect`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Rect.md)

The bounding box for this element. The coordinates of the bounding box are specified in user space coordinates, relative to the element's Content. Note that user space coordinates correspond to unrotated pages; any rotation specified in the page dictionary is not taken into account.

The bounding box for this element. The bounding box is a rectangle that is guaranteed to encompass the element, but it is not guaranteed to be the smallest box that could contain the element. For example, if the element is a Path that contains an arc, the bounding box encompasses the bezier control points, and not just the curve itself.

### getBoundingBoxForCharacter

```java
Rect com.datalogics.PDFL.Text.getBoundingBoxForCharacter(int characterIndex)
```

**Parameters**

- `characterIndex` (`int`): The index of a character, relative to the Text object (the first character in the Text object is at index 0)

**Returns:** [`Rect`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Rect.md)

A Rect specifying the bounding box for the character.

The bounding box for a character in this text element.

### getClip

```java
Clip com.datalogics.PDFL.Element.getClip()
```

**Returns:** [`Clip`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Clip.md)

The current Clip for this Element, or NULL if no clip is set.

Gets the current Clip for an Element.

### getMatrix

```java
Matrix com.datalogics.PDFL.Element.getMatrix()
```

**Returns:** [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)

The current transformation matrix applied to this element.

The transformation matrix for the element.

### getNumberOfCharacters

```java
int com.datalogics.PDFL.Text.getNumberOfCharacters()
```

**Returns:** `int`

The number of characters in this text element.

### getNumberOfRuns

```java
int com.datalogics.PDFL.Text.getNumberOfRuns()
```

**Returns:** `int`

The number of text runs in this text element.

### getRun

```java
TextRun com.datalogics.PDFL.Text.getRun(int index)
```

**Parameters**

- `index` (`int`): The zero-based index of the TextRun to retrieve.

**Returns:** [`TextRun`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/TextRun.md)

The TextRun at the specified index.

Obtains the TextRun at the specified index.

### getTextMatrixForCharacter

```java
Matrix com.datalogics.PDFL.Text.getTextMatrixForCharacter(int characterIndex)
```

**Parameters**

- `characterIndex` (`int`): The index of a character, relative to the Text object (the first character in the Text object is at index 0).

**Returns:** [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)

The transformation matrix for the character specified by characterIndex.

Gets the transformation matrix from user space to the current text space for the specified character. The H and V values of the matrix indicate the origin of the first character.

### getTextMatrixForTextRun

```java
Matrix com.datalogics.PDFL.Text.getTextMatrixForTextRun(int textRunIndex)
```

**Parameters**

- `textRunIndex` (`int`): The index of a TextRun, relative to the Text object (the first TextRun in the Text object is at index 0).

**Returns:** [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)

The transformation matrix for the TextRun specified by TextRunIndex.

Gets the transformation matrix from user space to the current text space for the specified TextRun. The H and V values of the matrix indicate the origin of the first character.

### pointIntersectsCharacter

```java
boolean com.datalogics.PDFL.Text.pointIntersectsCharacter(Point p, int index)
```

**Parameters**

- `p` ([`Point`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Point.md)): The point to test, in user space coordinates.
- `index` (`int`): The index of the character. The first character in the Text has an index of 0.

**Returns:** `boolean`

true if the point is on the character, false if the point is not on the character.

Tests whether a point is on a specified character within this Text object.

### pointIntersectsTextRun

```java
boolean com.datalogics.PDFL.Text.pointIntersectsTextRun(Point p, int index)
```

**Parameters**

- `p` ([`Point`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Point.md)): The point to test, in user space coordinates.
- `index` (`int`): The index of the TextRun. The first TextRun in the Text has an index of 0.

**Returns:** `boolean`

true if the point is on the TextRun, false if the point is not on the TextRun.

Tests whether a point is on a specified TextRun within this Text object.

### rectIntersectsCharacter

```java
boolean com.datalogics.PDFL.Text.rectIntersectsCharacter(Rect r, int index)
```

**Parameters**

- `r` ([`Rect`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Rect.md)): The rect to test, in user space coordinates.
- `index` (`int`): The index of the character. The first character in the Text has an index of 0.

**Returns:** `boolean`

true if any part of the rectangle is on the character, false if no part of the rectangle is on the character.

Tests whether any part of a rectangle is on a specified character within this Text object.

### rectIntersectsTextRun

```java
boolean com.datalogics.PDFL.Text.rectIntersectsTextRun(Rect r, int index)
```

**Parameters**

- `r` ([`Rect`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Rect.md)): The rect to test, in user space coordinates.
- `index` (`int`): The index of the TextRun. The first TextRun in the Text has an index of 0.

**Returns:** `boolean`

true if any part of the rectangle is on the TextRun, false if no part of the rectangle is on the TextRun.

Tests whether any part of a rectangle is on a specified TextRun within this Text object.

### removeRuns

```java
void com.datalogics.PDFL.Text.removeRuns(int index, int count)
```

**Parameters**

- `index` (`int`): Start position of range to delete
- `count` (`int`): Count of TextRuns to delete

**Returns:** `void`

Removes a count of TextRuns, starting from index

### rotate

```java
void com.datalogics.PDFL.Element.rotate(double theta)
```

**Parameters**

- `theta` (`double`): The rotation angle in degrees.

**Returns:** `void`

Rotate an element by theta degrees counterclockwise using the matrix [ cos T sin T -sin T cos T 0 0 ].

### scale

```java
void com.datalogics.PDFL.Element.scale(double sx, double sy)
```

**Parameters**

- `sx` (`double`): The horizontal scale factor.
- `sy` (`double`): The vertical scale factor.

**Returns:** `void`

Scale an element by (sx,sy) units using the matrix [ sx 0 0 sy 0 0 ].

### setClip

```java
void com.datalogics.PDFL.Element.setClip(Clip clip)
```

**Parameters**

- `clip` ([`Clip`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Clip.md)): The clip to set as the current clip for this element, or NULL to remove clipping.

**Returns:** `void`

Sets the current Clip for an Element.

### setMatrix

```java
void com.datalogics.PDFL.Element.setMatrix(Matrix matrix)
```

**Parameters**

- `matrix` ([`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)): The transformation matrix for the element.

**Returns:** `void`

Set the transformation matrix for the element.

### splitTextRunAtCharacter

```java
void com.datalogics.PDFL.Text.splitTextRunAtCharacter(int splitLocation)
```

**Parameters**

- `splitLocation` (`int`): The split location, relative to the Text object.

**Returns:** `void`

Splits the TextRun containing the character at the specified location into two contiguous TextRuns. The character at the specified index will be part of the first TextRun.

### translate

```java
void com.datalogics.PDFL.Element.translate(double tx, double ty)
```

**Parameters**

- `tx` (`double`): The horizontal translation distance in user space units.
- `ty` (`double`): The vertical translation distance in user space units.

**Returns:** `void`

Translate an element by (tx,ty) units using the matrix [ 1 0 0 1 tx ty ].
