How to Select and Copy the PDF Document's Content
- 4 minutes to read
In addition to viewing, navigating and printing the loaded document, you can copy its content, if the content extraction capabilities are not disabled. The PDF Viewer provides two document content extraction techniques:
Selecting and copying specific content to the clipboard;
Direct extraction of the page’s content from the internal representation of the loaded PDF document.
The more user-oriented document content extraction to the clipboard is described below while the direct approach to extraction is discussed in the How to Extract Content from PDF Documents topic.
To access the content selection management API, use the PDF Viewer’s Selection property. For instance, to select the entire document text or an arbitrary content on the displayed page (an image, image part, or a portion of text) you can call the Selection.SelectAll, Selection.SelectText, or Selection.Select procedure, respectively. The latter procedure selects the content located within the specified rectangular portion of the document view area. Note that if both an image and text are present within the rectangle, the procedure selects only text. Regardless of the approach used, you can select only one image or image part at a time.
If an image or text is currently selected, you can extract the selection as a bitmap object or text string by calling the Selection.AsBitmap or Selection.AsText functions, respectively.
If the selection is empty or does not contain an image or text, or the content extraction operations are forbidden, the AsBitmap and AsText function return nil and an empty string, respectively.
To clear the current selection, call the Selection.Clear procedure.
To specify which content is available for selection, use the control’s OptionsSelection.Annotations, OptionsSelection.Images, and OptionsSelection.Text properties.
In addition to the public API methods, the PDF Viewer provides multiple end-user document selection options that include the capability to select:
All the text in the document by executing the SelectAll command, clicking the “Select All” item in the PDF Viewer’s context menu, or pressing the Ctrl+A key combination (these options are available even when the Hand Tool is active, unlike the other end-user selection techniques):
Any whole image in the document by clicking it:
A rectangular portion of an image by clicking and dragging inside it:
A single word, a text line, or all the text on a single page by double-, triple-, or quadruple-clicking within a visible text line, respectively:
Any portion of text within the document by positioning and moving the caret by pressing the respective navigation and selection keystrokes:
Caret Operations | Keystrokes |
---|---|
Move the caret one character left or right from the current position. | The Right and Left keys. |
Move the caret up or down one text line from the current position. | The Up and Down keys. |
Move the caret to the beginning or end of the current text line in the document. | The Home and End keys. |
Move the caret to the beginning of the first text line or the end of the last text line in the document. | The Ctrl+Home and Ctrl+End key combinations. |
Move the caret left or right between individual words within the current text line. | The Ctrl+Left and Ctrl+Right key combinations. |
Expand the text selection to the beginning or end of the document. | The Ctrl+Shift+Home and Ctrl+Shift+End key combinations. |
Expand the text selection one word to the left or right. | The Ctrl+Shift+Left and Ctrl+Shift+Right key combinations. |
Expand the text selection left or right by one character. | The Shift+Left and Shift+Right key combinations. |
Expand the text selection up or down by one line. | The Shift+Up and Shift+Down key combinations. |
To copy the current document selection to the clipboard, you can call the Selection.CopyToClipboard procedure provided by the PDF Viewer.
End-users can click the “Copy Image” or “Copy” item in the PDF Viewer’s context menu to copy the selected image or text to the clipboard:
Pressing the Ctrl+C key combination copies any selected content to the clipboard.