Text search

The FindTextToolbar class allows the user to enter and search text in a document. Search results are automatically highlighted in the document and floating buttons allow searching forward or backward through the document. The core find text toolbar functionality is provided by the PTPDFViewCtrl's text search methods.

The find text toolbar is part of the Tools library, so make sure you have added the Tools library to your project.

Showing/hiding the Find Text toolbar

To create and set up a Find Text toolbar, supply a PTPDFViewCtrl instance to the FindTextToolbar designated initializer and add the toolbar to your view hierarchy:



When the find text toolbar is shown, the searchBarBecomeFirstResponder method should be called to focus the search bar and show the keyboard.

Highlighting search results

In order for search results to be highlighted on the page, the pdfViewCtrl:textSearchResult: method of the PTPDFViewCtrlDelegate protocol must be implemented by the adopting class, usually the containing view controller:



The Find Text Toolbar Delegate

The FindTextToolbarDelegate protocol allows the adopting class (usually the containing view controller, as in this guide) to be notified of find text toolbar events. Since this protocol also conforms to the UIToolbarDelegate protocol, the find text toolbar's delegate can implement the positionForBar: method to indicate the toolbar position: