Skip to main content

PdfViewerControl.GetText(PdfDocumentArea) Method

Gets the text contained in the specified document area.

Namespace: DevExpress.Xpf.PdfViewer

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

NuGet Package: DevExpress.Wpf.PdfViewer


public string GetText(
    PdfDocumentArea area


Name Type Description
area PdfDocumentArea

A PdfDocumentArea value.


Type Description

The text contained in the specified document area.


The GetText method uses the page coordinate system.

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 pointer's initial position
        startPosition = pdfViewer.ConvertPixelToDocumentPosition(e.GetPosition(pdfViewer));
        endPosition = null;
        mouseButtonPressed = true;

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

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

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