|
1 | 1 | ---
|
2 | 2 | layout: post
|
3 |
| -title: Searching Text in WPF Pdf Viewer control | Syncfusion |
| 3 | +title: Search text in PDF files using WPF PDF Viewer | Syncfusion |
4 | 4 | description: Learn about Searching Text support in Syncfusion Essential Studio WPF Pdf Viewer control, its elements and more.
|
5 | 5 | platform: wpf
|
6 | 6 | control: PDF Viewer
|
7 | 7 | documentation: ug
|
8 | 8 | ---
|
9 | 9 |
|
10 |
| -# Searching Text in WPF Pdf Viewer |
| 10 | +# Search text in PDF files using WPF PDF Viewer |
11 | 11 |
|
12 |
| -Essential PDF Viewer allows you to search and highlight the text in the PDF document. The search box appears when Ctrl+F is pressed and searches the text in the PDF document as displayed in the following screenshot. |
| 12 | +The WPF PDF Viewer allows you to search and highlight the text in the PDF files. The search box appears when Ctrl+F is pressed and searches the text in the PDF document as displayed in the following screenshot. |
13 | 13 |
|
14 |
| - |
| 14 | + |
15 | 15 |
|
16 |
| -N> |
17 |
| -* PdfDocumentView is used to view the PDF documents without the toolbar. So, make use of PdfViewerControl to search the text using search box. |
| 16 | +N> [PdfDocumentView](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfDocumentView.html) is used to view the PDF documents without the toolbar. So, make use of [PdfViewerControl](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html) to search the text using search box. |
18 | 17 |
|
19 |
| -The PDF Viewer control also supports searching text in the PDF document using the following API. The [FindText](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_FindText_System_String_System_Collections_Generic_Dictionary_System_Int32_System_Collections_Generic_List_System_Drawing_RectangleF____) method returns true when the text given is found in the document. The dictionary contains the page index and the list of rectangular coordinates of the text found in that page. The following code example explains how text search can be achieved after [creating the control from the code](https://help.syncfusion.com/wpf/pdf-viewer/getting-started#creating-pdfviewercontrol-from-code) and handled in the Loaded event of the [application's MainWindow](https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.mainwindow?view=netframework-4.8). |
| 18 | +## Search text in PDF programmatically |
| 19 | + |
| 20 | +The WPF PDF Viewer also supports searching text in the PDF programmatically using the following API. The [FindText](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_FindText_System_String_System_Collections_Generic_Dictionary_System_Int32_System_Collections_Generic_List_System_Drawing_RectangleF____) method returns true when the text given is found in the document. The dictionary contains the page index and the list of rectangular coordinates of the text found in that page. The following code example explains how text search can be achieved after [creating the control from the code](https://help.syncfusion.com/wpf/pdf-viewer/getting-started#creating-pdfviewercontrol-from-code) and handled in the Loaded event of the [application's MainWindow](https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.mainwindow?view=netframework-4.8). |
20 | 21 |
|
21 | 22 | {% tabs %}
|
22 | 23 | {% highlight c# %}
|
23 |
| -private void Window_Loaded(object sender, RoutedEventArgs e) |
24 |
| -{ |
25 |
| - |
26 |
| - bool IsMatchFound; |
27 |
| - |
28 |
| - //Load the PDF. |
29 |
| - |
30 |
| - pdfViewerControl1.Load("../../Data/Barcode.pdf"); |
| 24 | + private void Window_Loaded(object sender, RoutedEventArgs e) |
| 25 | + { |
| 26 | + bool isMatchFound; |
31 | 27 |
|
32 |
| - //Get the occurrences of the target text and location. |
| 28 | + //Load the PDF. |
| 29 | + pdfViewer.Load("../../Data/Barcode.pdf"); |
33 | 30 |
|
34 |
| - Dictionary<int, List<RectangleF>> |
| 31 | + //Get the occurrences of the target text and location. |
| 32 | + Dictionary<int, List<RectangleF>> textSearch = new Dictionary<int, List<RectangleF>>(); |
35 | 33 |
|
36 |
| - textSearch = new Dictionary<int, List<RectangleF>>(); |
37 |
| - |
38 |
| - IsMatchFound = pdfViewerControl1.FindText("targetText", out textSearch); |
39 |
| - |
40 |
| -} |
| 34 | + isMatchFound = pdfViewer.FindText("targetText", out textSearch); |
| 35 | + } |
41 | 36 |
|
42 | 37 | {% endhighlight %}
|
43 |
| - |
44 | 38 | {% highlight vbnet %}
|
45 | 39 |
|
46 | 40 | Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
|
47 | 41 |
|
48 |
| - Dim IsMatchFound As Boolean |
| 42 | + Dim isMatchFound As Boolean |
49 | 43 |
|
50 | 44 | 'Load the PDF.
|
51 | 45 |
|
52 |
| - pdfViewerControl1.Load("../../Data/Barcode.pdf") |
| 46 | + pdfViewer.Load("../../Data/Barcode.pdf") |
53 | 47 |
|
54 | 48 | 'Get the occurrences of the target text and location.
|
55 | 49 |
|
56 | 50 | Dim textSearch As New Dictionary(Of Integer, List(Of RectangleF))()
|
57 | 51 |
|
58 |
| - IsMatchFound = pdfViewerControl1.FindText("targetText", textSearch) |
| 52 | + isMatchFound = pdfViewer.FindText("targetText", textSearch) |
59 | 53 |
|
60 | 54 | End Sub
|
61 | 55 |
|
|
0 commit comments