Text search can be done in two ways, by using the SearchText method or by using the commands.

In all code snippets found below, ‘buffer’ is the byte array read from the PDF file either using FileOpenPicker or from Assets folder, as illustrated in the Viewing PDF section.

Using search methods

The following code shows how to initiate the text search using the method.

private void Page_Loaded(object sender, RoutedEventArgs e)
{
    PdfLoadedDocument loadedDocument = new PdfLoadedDocument(buffer);
    pdfViewer.LoadDocument(loadedDocument);
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    //Searches for the text in the PDF Document.
    pdfViewer.SearchText("the");
}
Private Sub Page_Loaded(sender As Object, e As RoutedEventArgs)
    Dim loadedDocument As New PdfLoadedDocument(buffer)
    pdfViewer.LoadDocument(loadedDocument)
End Sub

Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    'Searches for the text in the PDF Document.
    pdfViewer.SearchText("the")
End Sub

The following code shows how to search for the next instance.

private void Page_Loaded(object sender, RoutedEventArgs e)
{
    PdfLoadedDocument loadedDocument = new PdfLoadedDocument(buffer);
    pdfViewer.LoadDocument(loadedDocument);
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    //Searches for the text in the PDF Document.
    pdfViewer.SearchNextText("the");
}
Private Sub Page_Loaded(sender As Object, e As RoutedEventArgs)
    Dim loadedDocument As New PdfLoadedDocument(buffer)
    pdfViewer.LoadDocument(loadedDocument)
End Sub

Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    'Searches for the text in the PDF Document.
    pdfViewer.SearchNextText("the")
End Sub

The following code shows how to search for the previous instance.

private void Page_Loaded(object sender, RoutedEventArgs e)
{
    PdfLoadedDocument loadedDocument = new PdfLoadedDocument(buffer);
    pdfViewer.LoadDocument(loadedDocument);
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    //Searches for the text in the PDF Document.
    pdfViewer.SearchPrevText("the");
}
Private Sub Page_Loaded(sender As Object, e As RoutedEventArgs)
    Dim loadedDocument As New PdfLoadedDocument(buffer)
    pdfViewer.LoadDocument(loadedDocument)
End Sub

Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    'Searches for the text in the PDF Document.
    pdfViewer.SearchPrevText("the")
End Sub

Using search commands

The following code shows how to search for the next instance using SearchNextCommand.

<Grid>
        <syncfusion:SfPdfViewerControl Name="pdfViewer"></syncfusion:SfPdfViewerControl>
        <Button Content="Search Next" Command="{Binding ElementName=pdfViewer, Path=SearchNextCommand}" CommandParameter="{Binding Text, ElementName=PageSearchTxtBox}"></Button>
</Grid>

The following code shows how to search for the previous instance using SearchPreviousCommand.

<Grid>
        <syncfusion:SfPdfViewerControl Name="pdfViewer"></syncfusion:SfPdfViewerControl>
        <Button Content="Search Next" Command="{Binding ElementName=pdfViewer, Path=SearchPreviousCommand}" CommandParameter="{Binding Text, ElementName=PageSearchTxtBox}"></Button>
</Grid>

NOTE

The text search operations can only be performed after the display of the PDF document in the viewer control and this cannot be initiated immediately after loading the PDF document.