# Text Position

The `TextPosition` class allows you to keep track of the current text caret position in the document.

> `TextPosition` is part of the [RadPdfProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview) library which is used for the document model of the PdfViewer.

The text position is useful for the UI only when you activate the `TextSelection` [viewer mode](https://www.telerik.com/winui/documentation/controls/radpdfviewer/user-interaction/viewer-modes). To do so, set the `Mode` property of the PdfViewer. For more information, refer to the article on the [PdfViewer interaction modes](https://www.telerik.com/winui/documentation/controls/radpdfviewer/user-interaction/viewer-modes).

#### **Select the TextSelection mode**

```C#
this.pdfViewer.Mode = FixedDocumentViewerMode.TextSelection;
```

When the text selection mode is active, the caret position can be changed by clicking on the text in the PDF document.

## Manual Text Positioning

To change the caret position manually, use the `CaretPosition` property of the `RadFixedDocument` class that can be accessed through the `Document` property of the PdfViewer. The caret position is represented by the `TextPosition` class which provides the following methods for updating the position:

* `MoveToNextPosition`
* `MoveToPreviousPosition`
* `MoveToPosition`
* `MoveToNextWord`
* `MoveToPreviousWord`
* `MoveToCurrentWordStart`
* `MoveToCurrentWordEnd`
* `MoveToLineStart`
* `MoveToLineEnd`
* `MoveLineUp`
* `MoveLineDown`
* `MoveToStartOfDocument`
* `MoveToEndOfDocument`

#### **Use the Move method**

```C#
this.pdfViewer.Document.CaretPosition.MoveToEndOfDocument();
```

Calling one of the `Move` methods will also scroll the document to bring the corresponding line into the viewport.

To select a position based on an position index in the document, initialize a new `TextPosition` object with the constructor overload where you provide a `RadFixedPage` and an offset.

#### **Move to a specific text position**

```C#
RadFixedDocument document = this.pdfViewer.Document;
RadFixedPage firstPage = document.Pages[0];

// This is the 100th character in the first page of the document.
TextPosition position = new TextPosition(firstPage, 100);            
this.pdfViewer.Document.CaretPosition.MoveToPosition(position);
```

## Events

`TextPosition` provides the `PositionChanging` and `PositionChanged` events that can be used to listen for changes in the position.

#### **Subscribe to position-changing events**

```C#
void SubscribeToEvents()
{
	this.pdfViewer.Document.CaretPosition.PositionChanged += Position_PositionChanged;
	this.pdfViewer.Document.CaretPosition.PositionChanging += Position_PositionChanging;
}

private void Position_PositionChanging(object sender, EventArgs e)
{            
}

private void Position_PositionChanged(object sender, EventArgs e)
{
}
```

## See Also

* [Text Selection](https://www.telerik.com/winui/documentation/controls/radpdfviewer/user-interaction/text-selection)
* [Scrolling](https://www.telerik.com/winui/documentation/controls/radpdfviewer/user-interaction/scrolling)
* [Interaction Modes](https://www.telerik.com/winui/documentation/controls/radpdfviewer/user-interaction/viewer-modes)
* [Toolbar](https://www.telerik.com/winui/documentation/controls/radpdfviewer/toolbar)
