Skip to main content
A newer version of this page is available. .

PdfViewer.Select(PdfDocumentPosition, PdfDocumentPosition) Method

Selects the document content located at the specified position.

Namespace: DevExpress.XtraPdfViewer

Assembly: DevExpress.XtraPdfViewer.v19.1.dll

Declaration

public void Select(
    PdfDocumentPosition startPosition,
    PdfDocumentPosition endPosition
)

Parameters

Name Type Description
startPosition PdfDocumentPosition

A PdfDocumentPosition value, specifying the starting position in the document.

endPosition PdfDocumentPosition

A PdfDocumentPosition value, specifying the ending position in the document.

Remarks

The overloaded Select method uses the page coordinate system. See the Coordinate Systems topic to learn more.

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