PdfViewer.Select(PdfDocumentPosition, PdfDocumentPosition) Method
In This Article
Selects the textual content located at the specified position.
Namespace: DevExpress.XtraPdfViewer
Assembly: DevExpress.XtraPdfViewer.v24.2.dll
NuGet Package: DevExpress.Win.PdfViewer
#Declaration
public void Select(
PdfDocumentPosition startPosition,
PdfDocumentPosition endPosition
)
#Parameters
Name | Type | Description |
---|---|---|
start |
Pdf |
A Pdf |
end |
Pdf |
A Pdf |
#Remarks
The overloaded Select method uses the page coordinate system. See the Coordinate Systems topic to learn more.
If the part of the image is located between the specified positions, the method selects nothing.
bool mouseButtonPressed = false;
PdfDocumentPosition startPosition;
PdfDocumentPosition endPosition;
void pdfViewer1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//Retrieve the cursor's initial position
startPosition = pdfViewer1.GetDocumentPosition(e.Location);
endPosition = null;
mouseButtonPressed = true;
pdfViewer1.Invalidate();
}
}
void pdfViewer1_MouseMove(object sender, MouseEventArgs e)
{
if (mouseButtonPressed)
{
//Obtain the cursor's final position
endPosition = pdfViewer1.GetDocumentPosition(e.Location);
pdfViewer1.Invalidate();
}
}
void pdfViewer1_MouseUp(object sender, MouseEventArgs e)
{
mouseButtonPressed = false;
if (startPosition == null || endPosition == null)
return;
var start = pdfViewer1.GetClientPoint(startPosition);
var end = pdfViewer1.GetClientPoint(endPosition);
//Select the content between two positions
pdfViewer1.Select(startPosition, endPosition);
PdfSelectionContent content = pdfViewer1.GetSelectionContent();
//If the selection contains text, copy it to Clipboard
if (content.ContentType == PdfSelectionContentType.Text)
pdfViewer1.CopyToClipboard();
MessageBox.Show("The selection is copied to Clipboard");
}
See Also