Some test text!

menu
search
Text searchkeyboard_arrow_down

Text search

There are two parts to text searching. First is the UI component that is presented to the user. Second is an API guide to perform the text search functionality.

Text search UI

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

Text Search

The search view controller is part of the Tools library, so make sure you have added the Tools library to your project.

linkShowing a text search view controller

To create and set up a text search view controller, supply a PTPDFViewCtrl instance to the PTTextSearchViewController designated initializer:

let textSearchViewController = PTTextSearchViewController(pdfViewCtrl: pdfViewCtrl)
textSearchViewController.delegate = self

let navigationController = UINavigationController(rootViewController: textSearchViewController)
if ( UIDevice.current.userInterfaceIdiom == .pad ) {
    navigationController.modalPresentationStyle = .popover
    navigationController.popoverPresentationController?.barButtonItem = searchButton
} else {
    navigationController.modalPresentationStyle = .custom
}

self.present(navigationController, animated: true, completion: nil)
The search view controller does not create its own top navigation bar, so it must be pushed onto a navigation controller's stack.
Presenting on iPads:
The search view controller is designed to be presented in a popover on iPads. To do so, you must provide the PTTextSearchViewController's UIPopoverPresentationController with either: OR as in the example above.

linkSearch results list view

The PTTextSearchViewController also presents the search results in a UITableView for fast and easy navigation. Selecting any result in the table view will immediately navigate to that result and highlight it.

Text Search

linkSearch options

The PTTextSearchViewController interface also allows the user to refine the search to be case-sensitive, or to match whole words only:

Text Search

linkThe text search view controller delegate

The PTTextSearchViewControllerDelegate protocol allows the adopting class (usually the containing view controller, as in this guide) to be notified when the view controller has been dismissed. This can be used to show or hide other content as appropriate.

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more
close