wpf-devexpress-dot-xpf-dot-pdfviewer-dot-pdfviewercontrol-dot-gettext-x28-devexpress-dot-pdf-dot-pdfdocumentarea-x29.md
Gets the text contained in the specified document area.
Namespace : DevExpress.Xpf.PdfViewer
Assembly : DevExpress.Xpf.PdfViewer.v25.2.dll
NuGet Package : DevExpress.Wpf.PdfViewer
public string GetText(
PdfDocumentArea area
)
Public Function GetText(
area As PdfDocumentArea
) As String
| Name | Type | Description |
|---|---|---|
| area | PdfDocumentArea |
A PdfDocumentArea value.
|
| Type | Description |
|---|---|
| String |
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
e.GetPosition(pdfViewer);
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)
return;
//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));
}
Private mouseButtonPressed As Boolean = False
Private startPosition As PdfDocumentPosition
Private endPosition As PdfDocumentPosition
Private Sub pdfViewer1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
If e.LeftButton = MouseButtonState.Pressed Then
e.GetPosition(pdfViewer)
' Obtain the pointer's initial position
startPosition = pdfViewer.ConvertPixelToDocumentPosition(e.GetPosition(pdfViewer))
endPosition = Nothing
mouseButtonPressed = True
End If
End Sub
Private Sub pdfViewer1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
If mouseButtonPressed Then
'Retrieve the pointer's final position
endPosition = pdfViewer.ConvertPixelToDocumentPosition(e.GetPosition(pdfViewer))
End If
End Sub
Private Sub pdfViewer1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
mouseButtonPressed = False
If startPosition Is Nothing OrElse endPosition Is Nothing Then Return
' Get text located between two positions
Dim text As String = pdfViewer.GetText(PdfDocumentArea.Create(startPosition, endPosition))
MessageBox.Show(String.Format("You selected the following text:" & vbCrLf & " {0}", text))
End Sub
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetText(PdfDocumentArea) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
wpf-pdf-viewer-draw-a-rectangle-over-a-document/CS/MainWindow.xaml.cs#L35
txtText.Text = pdfView.GetText(pdfDocumentArea);
txtPositions.Text = $"Start position: {args.StartPosition.Point.X}, {args.StartPosition.Point.Y}\nEnd Position: " +
wpf-pdf-viewer-draw-a-rectangle-over-a-document/VB/MainWindow.xaml.vb#L24
Dim pdfDocumentArea As PdfDocumentArea = New PdfDocumentArea(args.StartPosition.PageNumber, rect)
Me.txtText.Text = Me.pdfView.GetText(pdfDocumentArea)
Me.txtPositions.Text = $"Start position: {args.StartPosition.Point.X}, {args.StartPosition.Point.Y}
See Also