New to Telerik UI for .NET MAUI? Start a free 30-day trial

.NET MAUI PDF Viewer Search Programmatically

The PDF Viewer for .NET MAUI allows you to programmatically search in the document.

Manual Searching

You can use the SearchAsync method of the SearchSettings to manually initiate an async search operation with the provided text and search options.

Here is an example with the SearchAsync method and custom buttons for programmatically navigating to the next and previous search results:

1. Define the PDF Viewer control in XAML:

<Grid RowDefinitions="Auto, *" RowSpacing="20">
    <HorizontalStackLayout Spacing="10">
        <telerik:RadEntry x:Name="searchEntry" Placeholder="Enter text to search" ReserveSpaceForErrorView="False" TextChanged="OnSearchEntryTextChanged"  WidthRequest="{OnIdiom Default=200, Desktop=300}" />
        <telerik:RadButton Text="&#xf106;" Command="{Binding NavigateToPreviousSearchResultCommand, Source={x:Reference pdfViewer}}" />
        <telerik:RadButton Text="&#xf107;" Command="{Binding NavigateToNextSearchResultCommand, Source={x:Reference pdfViewer}}" />
    </HorizontalStackLayout>
    <telerik:RadPdfViewer x:Name="pdfViewer" Grid.Row="1" />

2. Add the following namespace:

xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"

3. The TextChanged implementation where the SearchAsync method is used:

private void OnSearchEntryTextChanged(object sender, TextChangedEventArgs e)
{
    this.pdfViewer.SearchSettings.SearchAsync(this.searchEntry.Text, this.pdfViewer.SearchSettings.SearchOptions);
}

The following video shows the results from the completed example on Android:

.NET MAUI PdfViewer Search Programmatically

For the runnable PDF Viewer Search Programmatic example, see the SDKBrowser Demo Application and go to PdfViewer > Search category.

See Also

In this article