Text search in Blazor PDF Viewer

17 Jul 20261 minute to read

The Blazor PDF Viewer provides an integrated text search experience that supports both interactive UI search and programmatic searches. Enable the feature by setting EnableTextSearch to true. To start a search programmatically, call SearchTextAsync.

Enable text search as shown below.

@using Syncfusion.Blazor.SfPdfViewer

<SfPdfViewer2 EnableTextSearch="true"
             DocumentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
             Height="100%"
             Width="100%">
</SfPdfViewer2>

The text search functionality allows you to retrieve and locate content within PDF documents with case-sensitive or case-insensitive matching, enabling integration with search analytics and downstream processing workflows.

Key capabilities

  • Text search UI: Search from the toolbar with the Match Case option and navigation controls.
  • Text search programmatic APIs: Start a search with SearchTextAsync, which accepts the search text and an isMatchCase flag for case sensitivity. SearchNextAsync and SearchPreviousAsync navigate to the next and previous occurrence of the most recent search query. CancelTextSearchAsync cancels the current search and removes the highlighted occurrences.
  • Text search events: OnTextSearchStart fires when a search begins, OnTextSearchHighlight fires for each match brought into view, and OnTextSearchComplete fires when the search finishes. Wire up an event handler as shown below.
@using Syncfusion.Blazor.SfPdfViewer

<SfPdfViewer2 DocumentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
             Height="100%"
             Width="100%">
    <PdfViewerEvents OnTextSearchComplete="OnTextSearchComplete"></PdfViewerEvents>
</SfPdfViewer2>

@code {
    private void OnTextSearchComplete(TextSearchCompleteEventArgs args)
    {
        // Handle search completion
    }
}

Further reading