Text selection API and events in React PDF Viewer
13 Jul 20262 minutes to read
This document provides the reference details for text selection APIs and events in the React PDF Viewer. It includes the programmatic methods and event callbacks that allow applications to react to selection behavior.
Methods
selectTextRegion
Programmatically selects text within a specified page and bounds.
Method signature:
selectTextRegion(pageNumber: number, bounds: IRectangle[]): voidParameters:
- pageNumber: number indicating the target page (1 based indexing)
- bounds:
IRectanglearray defining the selection region
Example:
pdfviewer.textSelection.selectTextRegion(3, [
{
left: 121.07501220703125,
right: 146.43399047851562,
top: 414.9624938964844,
bottom: 430.1625061035156,
width: 25.358978271484375,
height: 15.20001220703125
}
]);copyText
Copies the currently selected text to the clipboard.
Method signature:
copyText(): voidExample:
pdfviewer.textSelection.copyText();Events
textSelectionStart
Triggered when the user begins selecting text.
The event arguments are typed as TextSelectionStartEventArgs and expose the following members:
-
pageNumber– Page where the selection started (1-based indexing). -
name– Event name identifier.
Example:
<PdfViewerComponent
textSelectionStart={(args: TextSelectionStartEventArgs) => {
// custom logic
}}
>
</PdfViewerComponent>textSelectionEnd
Triggered when the user completes a text selection.
The event arguments are typed as TextSelectionEndEventArgs and expose the following members:
-
pageNumber– Page where the selection ended (1-based indexing). -
name– Event name identifier. -
textContent– The full text extracted from the selection range. -
textBounds– Array of bounding rectangles that define the geometric region of the selected text. Useful for custom UI overlays or programmatic re-selection.
Example:
<PdfViewerComponent
textSelectionEnd={(args: TextSelectionEndEventArgs) => {
// custom logic
}}
>
</PdfViewerComponent>