New to Telerik UI for WinUI? Download free 30-day trial

Text Position

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

TextPosition is part of the RadPdfProcessing library which is used for the document model of the PdfViewer.

The text position is meaningful for the UI only when you activate the TextSelection viewer mode. To do so, set the Mode property of RadPdfViewer.

Selecting the TextSelection mode

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.

To change the caret position manually, use the CaretPosition property of the RadFixedDocument class that can be accessed via the Document property of RadPdfViewer. The caret position is represented by the TextPosition class which provides the following methods that can be used to update the position.

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

Using a move method

Calling one of the move methods will also scroll the document in order to bring the corresponding line into the viewport.

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

Moving to a specific text position

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);             


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

Subscribe to position changing events

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

In this article
Not finding the help you need?