Searching Text in WPF Pdf Viewer

4 Sep 2020 / 1 minute to read

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.

Concept and Features


  • PdfDocumentView is used to view the PDF documents without the toolbar. So, make use of PdfViewerControl to search the text using search box.

The PDF Viewer control also supports searching text in the PDF document using the following API. The FindText 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 and handled in the Loaded event of the application’s MainWindow.

private void Window_Loaded(object sender, RoutedEventArgs e)

	bool IsMatchFound;

	//Load the PDF.


	//Get the occurrences of the target text and location.

	Dictionary<int, List<RectangleF>> 

          textSearch = new Dictionary<int, List<RectangleF>>();

	IsMatchFound = pdfViewerControl1.FindText("targetText", out textSearch);

Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)

	Dim IsMatchFound As Boolean

	'Load the PDF.


	'Get the occurrences of the target text and location.

	Dim textSearch As New Dictionary(Of Integer, List(Of RectangleF))()

	IsMatchFound = pdfViewerControl1.FindText("targetText", textSearch)

End Sub