Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

PdfViewerControl.GetText(PdfDocumentPosition, PdfDocumentPosition) Method

Gets the text contained in the specified document area.

Namespace: DevExpress.Xpf.PdfViewer

Assembly: DevExpress.Xpf.PdfViewer.v24.2.dll

NuGet Package: DevExpress.Wpf.PdfViewer

#Declaration

public string GetText(
    PdfDocumentPosition start,
    PdfDocumentPosition end
)

#Parameters

Name Type Description
start PdfDocumentPosition

A PdfDocumentPosition object that is the top left point of a document area.

end PdfDocumentPosition

A PdfDocumentPosition object that is the bottom right point of a document area.

#Returns

Type Description
String

The text contained in the specified document area.

#Remarks

The GetText method uses the page coordinate system. The method returns the text range marked by the method parameters.

You can select the text from code using the PdfViewerControl.Select method. Call the PdfViewer.GetSelectionContent() method to retrieve the selected text.

The code sample below retrieves the text located under the mouse selection.

bool mouseButtonPressed = false;
PdfDocumentPosition startPosition;
PdfDocumentPosition endPosition;

void pdfViewer1_MouseDown(object sender, MouseEventArgs e)

{
    if (e.LeftButton == MouseButtonState.Pressed)
    {
        //Retrieve the cursor's initial position
        e.GetPosition(pdfViewer);
        startPosition = pdfViewer.ConvertPixelToDocumentPosition(e.GetPosition(pdfViewer));
        endPosition = null;
        mouseButtonPressed = true;
    }
}

void pdfViewer1_MouseMove(object sender, MouseEventArgs e)
{
    if (mouseButtonPressed)
    {
        //Obtain the cursor's final position
        endPosition = pdfViewer.ConvertPixelToDocumentPosition(e.GetPosition(pdfViewer));
    }
}


void pdfViewer1_MouseUp(object sender, MouseEventArgs e)
{
    mouseButtonPressed = false;
    if (startPosition == null || endPosition == null)
        return;

    //Retrieve the content between two positions
    string text = pdfViewer.GetText(startPosition, endPosition);
    MessageBox.Show(string.Format("You selected the following text:\r\n {0}", text));
}
See Also