# TextRun Class

> Represents one or more contiguous characters in a text object.

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

```java
class TextRun : Element
```

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

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

## Description

Represents one or more contiguous characters in a text object. All the characters contained within a text run have the same style, color, font, and size.

**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), [`Element`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Element.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), [`Rect`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Rect.md), [`TextState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/TextState.md)

## Constructors

### TextRun

```java
com.datalogics.PDFL.TextRun.TextRun(String text, Font font, GraphicState gstate, TextState tstate, Matrix matrix)
```

*constructor*

**Parameters**

- `text` (`String`): The text content for this run.
- `font` ([`Font`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Font.md)): The font to use for rendering the text.
- `gstate` ([`GraphicState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/GraphicState.md)): The graphic state (colors, line width, etc.) for this text run.
- `tstate` ([`TextState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/TextState.md)): The text state (character spacing, word spacing, font size, etc.) for this text run.
- `matrix` ([`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)): The transformation matrix positioning this text run in user space.

Creates a new TextRun with the specified text, font, graphic state, text state, and matrix.

## Methods

### clone

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

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

The copied element.

Makes a copy of the element.

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

Note: TextRun objects may not be cloned.

### clone

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

**Parameters**

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

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

The copied element.

Makes a copy of the element.

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

Note: TextRun objects may not be cloned.

### delete

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

*protected*

**Parameters**

- `disposing` (`Boolean`)

**Returns:** `synchronized void`

### delete

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

**Returns:** `synchronized void`

### finalize

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

*protected*

**Returns:** `void`

### getAdvance

```java
double com.datalogics.PDFL.TextRun.getAdvance()
```

**Returns:** `double`

The advance width of this text run.

Deprecated, use Text.GetAdvanceForTextRun(int textRunIndex) instead. This version does not indicate the direction of the advance width.

The advance width of this run of text, in user space.

The advance width is the amount by which the current point advances when the text run is drawn.

### 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.

### 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.

### getFont

```java
Font com.datalogics.PDFL.TextRun.getFont()
```

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

The font for this text run.

The font used to render this TextRun.

### getGraphicState

```java
GraphicState com.datalogics.PDFL.TextRun.getGraphicState()
```

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

The GraphicState for this text run, or null.

The graphic state (colors, line width, etc.) of the text run.

May return null if this element does not have a GraphicState.

### 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.

### getRawText

```java
byte[] com.datalogics.PDFL.TextRun.getRawText()
```

**Returns:** `byte[]`

A byte array containing the raw character codes.

The raw, un-interpreted text as character codes of this TextRun.

### getText

```java
String com.datalogics.PDFL.TextRun.getText()
```

**Returns:** `String`

The text string for this run.

The Unicode text content of this TextRun.

### getTextState

```java
TextState com.datalogics.PDFL.TextRun.getTextState()
```

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

The TextState for this text run.

The text state parameters (character spacing, word spacing, font size, etc.) of this TextRun.

### 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.

### setFont

```java
void com.datalogics.PDFL.TextRun.setFont(Font font)
```

**Parameters**

- `font` ([`Font`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Font.md)): The new font for this text run.

**Returns:** `void`

The font used to render this TextRun.

### setGraphicState

```java
void com.datalogics.PDFL.TextRun.setGraphicState(GraphicState gstate)
```

**Parameters**

- `gstate` ([`GraphicState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/GraphicState.md)): the new/updated Graphic State for the text run.

**Returns:** `void`

Set the Graphic State of the text run.

### 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.

### setText

```java
void com.datalogics.PDFL.TextRun.setText(String text)
```

**Parameters**

- `text` (`String`): The new text content for this run.

**Returns:** `void`

The Unicode text content of this 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 ].
