Skip to content

Commit f021877

Browse files
1032401: Text Search and Text Selection UG Documentation for Blazor PDF Viewer
1 parent 179a454 commit f021877

10 files changed

Lines changed: 625 additions & 1 deletion

File tree

Document-Processing-toc.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,18 @@
11411141
</ul>
11421142
</li>
11431143
<li> <a href="/document-processing/pdf/pdf-viewer/blazor/magnification">Magnification</a></li>
1144-
<li> <a href="/document-processing/pdf/pdf-viewer/blazor/text-search">Text Search</a></li>
1144+
<li><a href="/document-processing/pdf/pdf-viewer/blazor/text-search/overview">Text Search</a>
1145+
<ul>
1146+
<li><a href="/document-processing/pdf/pdf-viewer/blazor/text-search/text-search-features">Text Search</a></li>
1147+
<li><a href="/document-processing/pdf/pdf-viewer/blazor/text-search/text-search-events">Text Search Events</a></li>
1148+
</ul>
1149+
</li>
1150+
<li><a href="/document-processing/pdf/pdf-viewer/blazor/text-selection/overview">Text Selection</a>
1151+
<ul>
1152+
<li><a href="/document-processing/pdf/pdf-viewer/blazor/text-selection/enable-text-selection">Toggle text selection</a></li>
1153+
<li><a href="/document-processing/pdf/pdf-viewer/blazor/text-selection/text-selection-api-events">Text Selection API and Events</a></li>
1154+
</ul>
1155+
</li>
11451156
<li> <a href="/document-processing/pdf/pdf-viewer/blazor/interaction">Interaction Mode</a></li>
11461157
<li> <a href="/document-processing/pdf/pdf-viewer/blazor/hand-written-signature">Handwritten Signature</a></li>
11471158
<li>Annotations
26 KB
Loading
36.5 KB
Loading
15.7 KB
Loading
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
layout: post
3+
title: Text search and Extraction in Blazor PDF Viewer | Syncfusion
4+
description: Overview of text search capabilities, UI features, programmatic APIs, events and text extraction in the Syncfusion Blazor PDF Viewer.
5+
platform: document-processing
6+
control: Text search
7+
documentation: ug
8+
domainurl: ##DomainURL##
9+
---
10+
11+
# Text search and extraction in Blazor PDF Viewer
12+
13+
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`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerBase.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerBase_EnableTextSearch) as needed. To give more low-level information about text, methods like [`SearchTextAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_SearchTextAsync_System_String_System_Boolean_) can be used.
14+
15+
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.
16+
17+
## Key capabilities
18+
19+
- **Text search UI**: real‑time search from the toolbar, match‑case option, and search navigation controls.
20+
- **Text search programmatic APIs**: mirror UI behavior with [`SearchTextAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_SearchTextAsync_System_String_System_Boolean_), [`SearchNextAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_SearchNextAsync), [`SearchPreviousAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_SearchPreviousAsync), and [`CancelTextSearchAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_CancelTextSearchAsync).
21+
- **Text search events**: respond to [`OnTextSearchStart`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerEvents.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerEvents_OnTextSearchStart), [`OnTextSearchHighlight`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerEvents.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerEvents_OnTextSearchHighlight), and [`OnTextSearchComplete`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerEvents.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerEvents_OnTextSearchComplete) for UI sync, analytics, and custom overlays.
22+
23+
## When to use which API
24+
25+
- Use the toolbar/search panel for typical interactive searches and navigation.
26+
- Use [`SearchTextAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_SearchTextAsync_System_String_System_Boolean_) / [`SearchNextAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_SearchNextAsync) / [`SearchPreviousAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_SearchPreviousAsync) when driving search programmatically but keeping behavior consistent with the UI.
27+
- Use [`OnTextSearchStart`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerEvents.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerEvents_OnTextSearchStart), [`OnTextSearchHighlight`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerEvents.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerEvents_OnTextSearchHighlight), and [`OnTextSearchComplete`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerEvents.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerEvents_OnTextSearchComplete) events when you need to respond to search lifecycle changes for UI updates or logging.
28+
29+
## Further reading
30+
31+
- [Text Search Features](./text-search-features)
32+
- [Text Search Events](./text-search-events)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
layout: post
3+
title: Text search Events in Blazor PDF Viewer control | Syncfusion
4+
description: Learn how to handle text search events, and run programmatic searches in the Syncfusion Blazor PDF Viewer.
5+
platform: document-processing
6+
control: Text search
7+
documentation: ug
8+
domainurl: ##DomainURL##
9+
---
10+
11+
# Text Search Events in Blazor PDF Viewer
12+
13+
The Blazor PDF Viewer triggers events during text search operations, allowing you to customize behavior and respond to different stages of the search process.
14+
15+
## OnTextSearchStart
16+
17+
The [OnTextSearchStart](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerEvents.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerEvents_OnTextSearchStart) event fires as soon as a search begins from the toolbar interface or through the [`SearchTextAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_SearchTextAsync_System_String_System_Boolean_) method. Use to reset UI state, log analytics, or cancel the default search flow before results are processed.
18+
19+
- Event arguments: [TextSearchStartEventArgs](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.TextSearchStartEventArgs.html) exposes:
20+
- `SearchText`: the term being searched.
21+
- `MatchCase`: indicates whether case-sensitive search is enabled.
22+
23+
{% tabs %}
24+
{% highlight razor}
25+
@using Syncfusion.Blazor.SfPdfViewer
26+
<SfPdfViewer2 DocumentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
27+
Height="100%"
28+
Width="100%">
29+
<PdfViewerEvents OnTextSearchStart="OnTextSearchStart"></PdfViewerEvents>
30+
</SfPdfViewer2>
31+
32+
@code {
33+
private void OnTextSearchStart(TextSearchStartEventArgs args)
34+
{
35+
Console.WriteLine($"Text search started for: \"{args.SearchText}\"");
36+
}
37+
}
38+
{% endhighlight %}
39+
{% endtabs %}
40+
41+
## OnTextSearchHighlight
42+
43+
The [OnTextSearchHighlight](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerEvents.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerEvents_OnTextSearchHighlight) event triggers whenever a search result is brought into view, including navigation between matches. Use to draw custom overlays or synchronize adjacent UI elements when a match is highlighted.
44+
45+
- Event arguments: [TextSearchHighlightEventArgs](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.TextSearchHighlightEventArgs.html) exposes:
46+
- `Bound`: represents the highlighted match position and dimensions.
47+
- `PageNumber`: page index where the match is highlighted.
48+
49+
{% tabs %}
50+
{% highlight razor}
51+
@using Syncfusion.Blazor.SfPdfViewer
52+
<SfPdfViewer2 DocumentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
53+
Height="100%"
54+
Width="100%">
55+
<PdfViewerEvents OnTextSearchHighlight="OnTextSearchHighlight"></PdfViewerEvents>
56+
</SfPdfViewer2>
57+
58+
@code {
59+
private void OnTextSearchHighlight(TextSearchHighlightEventArgs args)
60+
{
61+
Console.WriteLine($"Highlighted match at page {args.PageNumber}, bounds: {args.Bound}");
62+
}
63+
}
64+
{% endhighlight %}
65+
{% endtabs %}
66+
67+
## OnTextSearchComplete
68+
69+
The [OnTextSearchComplete](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerEvents.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerEvents_OnTextSearchComplete) event runs after the search engine finishes scanning the document for the current query. Use to update match counts, toggle navigation controls, or notify users when no results were found.
70+
71+
- **Typical uses**:
72+
- Update UI with the total number of matches and enable navigation controls.
73+
- Hide loading indicators or show a "no results" message if none were found.
74+
- Record analytics for search effectiveness.
75+
- **Event arguments**: [TextSearchCompleteEventArgs](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.TextSearchCompleteEventArgs.html) exposes:
76+
- `SearchText`: the searched term.
77+
- `MatchCase`: indicates whether case-sensitive search was used.
78+
79+
{% tabs %}
80+
{% highlight razor}
81+
@using Syncfusion.Blazor.SfPdfViewer
82+
<SfPdfViewer2 DocumentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
83+
Height="100%"
84+
Width="100%">
85+
<PdfViewerEvents OnTextSearchComplete="OnTextSearchComplete"></PdfViewerEvents>
86+
</SfPdfViewer2>
87+
88+
@code {
89+
private void OnTextSearchComplete(TextSearchCompleteEventArgs args)
90+
{
91+
Console.WriteLine($"Text search completed for: \"{args.SearchText}\"");
92+
}
93+
}
94+
{% endhighlight %}
95+
{% endtabs %}
96+
97+
## See Also
98+
99+
- [Text Search Features](./text-search-features)
100+
- [Text Selection](../text-selection/overview)
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
---
2+
layout: post
3+
title: Text search in Blazor PDF Viewer Component | Syncfusion
4+
description: Learn how to configure text search and run programmatic searches in the Syncfusion Blazor PDF Viewer.
5+
platform: document-processing
6+
control: Text search
7+
documentation: ug
8+
domainurl: ##DomainURL##
9+
---
10+
11+
# Text search in Blazor PDF Viewer
12+
13+
The text search feature in the Blazor PDF Viewer locates and highlights matching content within a document. Enable or disable this capability with the following configuration.
14+
15+
![Text Search](../images/text-search.png)
16+
17+
N> The text search functionality requires setting [`EnableTextSearch`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerBase.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerBase_EnableTextSearch) property to `true`. Otherwise, the search UI and APIs will not be accessible.
18+
19+
## Text search features in UI
20+
21+
### Search text with the Match Case option
22+
23+
Enable the Match Case checkbox to limit results to case-sensitive matches. Navigation commands then step through each exact match in sequence.
24+
25+
![Text Search With Match Case](../images/text-search-matchcase.png)
26+
27+
### Search text without Match Case
28+
29+
Leave the Match Case option cleared to highlight every occurrence of the query, regardless of capitalization, and navigate through each result.
30+
31+
![Text Search Without Match Case](../images/text-search-without-matchcase.png)
32+
33+
## Programmatic text Search
34+
35+
The Blazor PDF Viewer provides options to toggle text search feature and APIs to customize the text search behavior programmatically.
36+
37+
### Enable or Disable Text Search
38+
39+
Use the following snippet to enable or disable text search features
40+
41+
{% tabs %}
42+
{% highlight razor%}
43+
@using Syncfusion.Blazor.SfPdfViewer
44+
45+
<SfPdfViewer2 EnableTextSearch="true"
46+
DocumentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
47+
Height="100%"
48+
Width="100%">
49+
</SfPdfViewer2>
50+
{% endhighlight %}
51+
{% endtabs %}
52+
53+
### Programmatic text search
54+
55+
While the PDF Viewer toolbar offers an interactive search experience, you can also trigger and customize searches programmatically by calling the following APIs.
56+
57+
#### `SearchTextAsync`
58+
59+
Use the [`SearchTextAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_SearchTextAsync_System_String_System_Boolean_) method to start a search with optional filters that control case sensitivity.
60+
61+
```cshtml
62+
// SearchTextAsync(string searchText, bool isMatchCase)
63+
await pdfViewer.SearchTextAsync("search text", false);
64+
```
65+
66+
Set the `isMatchCase` parameter to `true` to perform a case-sensitive search that mirrors the Match Case option in the search panel.
67+
68+
```cshtml
69+
// This will only find instances of "PDF" in uppercase.
70+
await pdfViewer.SearchTextAsync("PDF", true);
71+
```
72+
73+
#### `SearchNextAsync`
74+
75+
[`SearchNextAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_SearchNextAsync) method searches the next occurrence of the current query from the active match.
76+
77+
```cshtml
78+
// SearchNextAsync()
79+
await pdfViewer.SearchNextAsync();
80+
```
81+
82+
#### `SearchPreviousAsync`
83+
84+
[`SearchPreviousAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_SearchPreviousAsync) method searches the previous occurrence of the current query from the active match.
85+
86+
```cshtml
87+
// SearchPreviousAsync()
88+
await pdfViewer.SearchPreviousAsync();
89+
```
90+
91+
#### `CancelTextSearchAsync`
92+
93+
[`CancelTextSearchAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.SfPdfViewer2.html#Syncfusion_Blazor_SfPdfViewer_SfPdfViewer2_CancelTextSearchAsync) method cancels the current text search and removes the highlighted occurrences from the PDF Viewer.
94+
95+
```cshtml
96+
// CancelTextSearchAsync()
97+
await pdfViewer.CancelTextSearchAsync();
98+
```
99+
100+
#### Complete Example
101+
102+
Use the following code snippet to implement text search using SearchTextAsync API
103+
104+
{% tabs %}
105+
{% highlight razor %}
106+
<button @onclick="SearchText">Search Text</button>
107+
<button @onclick="PreviousSearch">Previous Search</button>
108+
<button @onclick="NextSearch">Next Search</button>
109+
<button @onclick="CancelSearch">Cancel Search</button>
110+
111+
<SfPdfViewer2 @ref="pdfViewer"
112+
DocumentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
113+
Height="100%"
114+
Width="100%">
115+
</SfPdfViewer2>
116+
117+
@code {
118+
private SfPdfViewer2 pdfViewer;
119+
120+
private async Task SearchText()
121+
{
122+
await pdfViewer.SearchTextAsync("pdf", false);
123+
}
124+
125+
private async Task PreviousSearch()
126+
{
127+
await pdfViewer.SearchPreviousAsync();
128+
}
129+
130+
private async Task NextSearch()
131+
{
132+
await pdfViewer.SearchNextAsync();
133+
}
134+
135+
private async Task CancelSearch()
136+
{
137+
await pdfViewer.CancelTextSearchAsync();
138+
}
139+
}
140+
{% endhighlight %}
141+
{% endtabs %}
142+
143+
**Expected result:** the viewer highlights occurrences of `pdf` and navigation commands jump between matches.
144+
145+
### Customize text search highlight colors
146+
147+
Use the [PdfViewerTextSearchColorSettings](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerTextSearchColorSettings.html) to customize the highlight appearance used for search results. Configure [SearchColor](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerTextSearchColorSettings.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerTextSearchColorSettings_SearchColor) for other matches and [SearchHighlightColor](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerTextSearchColorSettings.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerTextSearchColorSettings_SearchHighlightColor) for the current match. By default, distinct colors are applied for the current occurrence and other matches; adjust these to align with application theme and accessibility contrast requirements.
148+
149+
{% tabs %}
150+
{% highlight razor %}
151+
@using Syncfusion.Blazor.SfPdfViewer
152+
153+
<SfPdfViewer2 Height="100%" Width="100%" DocumentPath="@DocumentPath">
154+
<PdfViewerTextSearchColorSettings SearchColor="blue" SearchHighlightColor="red"></PdfViewerTextSearchColorSettings>
155+
</SfPdfViewer2>
156+
157+
@code{
158+
public string DocumentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";
159+
}
160+
{% endhighlight %}
161+
{% endtabs %}
162+
163+
164+
![Blazor SfPdfViewer text search highlight color customization](../images/blazor-pdfviewer-text-search-settings.png)
165+
166+
## See also
167+
168+
- [Text Search Events](./text-search-events)
169+
- [Text Selection](../text-selection/overview)

0 commit comments

Comments
 (0)