# pdf-viewer-text-search

> PDF viewer enables document text search with custom highlight colors and match navigation.

**Framework:** maui  **Component:** PdfViewer  **Variant:** text-search

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/maui/pdf-viewer-text-search.json
```

**Install Package(s)**

```bash
dotnet add package Syncfusion.Maui.PdfViewer
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/pdf-viewer-text-search/PdfViewer.xaml

```xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:pdf="clr-namespace:Syncfusion.Maui.PdfViewer;assembly=Syncfusion.Maui.PdfViewer"
             xmlns:model="clr-namespace:MAUI.Controls.PdfViewer.TextSearch"
             x:Class="MAUI.Controls.PdfViewer.TextSearch.PdfViewerView"
             x:DataType="model:PdfViewerViewModel"
             Title="PDF Viewer - Text Search">
    <ContentPage.Content>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="45"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <!-- Toolbar: Contains title and buttons for search actions -->
            <ScrollView Orientation="Horizontal"
                    HorizontalScrollBarVisibility="Never">
                <Grid ColumnDefinitions="Auto, *">
                    <!-- Title Label on the Left -->
                    <Label Text="PDF Viewer"
                            FontSize="16"
                            VerticalOptions="Center"
                            Grid.Column="0"/>

                    <!-- Button Container with Spacing -->
                    <HorizontalStackLayout Grid.Column="1"
                            Spacing="10"
                            HorizontalOptions="End"
                            Padding="0,0,15,0">
                        <Button Text="&#xE715;"
                                FontFamily="MauiMaterialAssets"
                                Clicked="SearchButtonClicked"/>
                        <!-- Starts search -->
                        <Button Text="&#xE707;"
                                FontFamily="MauiMaterialAssets"
                                Clicked="PreviousMatchButtonClicked"/>
                        <!-- Moves to previous match -->
                        <Button Text="&#xE706;"
                                FontFamily="MauiMaterialAssets"
                                Clicked="NextMatchButtonClicked"/>
                        <!-- Moves to next match -->
                        <Button Text="&#xE70B;"
                                FontFamily="MauiMaterialAssets"
                                Clicked="CloseSearchButtonClicked"/>
                        <!-- Clears search results -->
                    </HorizontalStackLayout>
                </Grid>
            </ScrollView>

            <!-- PDF Viewer Component -->
            <syncfusion:SfPdfViewer x:Name="PdfViewer"
                    ShowToolbars="False"
                    Grid.Row="1"
                    DocumentSource="{Binding DocumentStream}"/>
        </Grid>
    </ContentPage.Content>
</ContentPage>

```

### src/components/pdf-viewer-text-search/PdfViewer.xaml.cs

```cs
namespace MAUI.Controls.PdfViewer.TextSearch
{
    public partial class PdfViewerView : ContentPage
    {
        TextSearchResult? SearchResult;
        public PdfViewerView(PdfViewerViewModel viewModel)
        {
            InitializeComponent();
            BindingContext = viewModel;

            // Customize the highlight colors for search results.
            PdfViewer.TextSearchSettings.CurrentMatchHighlightColor = Color.FromRgba("#8F00FF43"); // Highlight color for the current match.
            PdfViewer.TextSearchSettings.OtherMatchesHighlightColor = Color.FromRgba("#00FF0043");  // Highlight color for other matches.
        }
        private void SearchButtonClicked(object sender, EventArgs e)
        {
            SearchText("the");
        }

        // Searches for the specified text asynchronously and stores the result.
        async void SearchText(string text)
        {
            PdfViewer.TextSearchProgress += PdfTextSearchProgress;
            SearchResult = await PdfViewer.SearchTextAsync(text);
        }

        private void PdfTextSearchProgress(object? sender, TextSearchProgressEventArgs? e)
        {
            if (e != null)
                // Cancel the search operation when it is running but does not need to be continued.
                e.SearchResult?.Clear();
        }

        // Moves to the next match when the next button is clicked.
        private void NextMatchButtonClicked(object sender, EventArgs e)
        {
            SearchResult?.GoToNextMatch();
        }

        // Moves to the previous match when the previous button is clicked.
        private void PreviousMatchButtonClicked(object sender, EventArgs e)
        {
            SearchResult?.GoToPreviousMatch();
        }

        // Clears the search highlights and resets the search state.
        private void CloseSearchButtonClicked(object sender, EventArgs e)
        {
            SearchResult?.Clear();
        }
    }
}

```
