Pre-populate search text

28 views
Skip to first unread message

Randy Haid

unread,
Feb 11, 2021, 4:09:08 PM2/11/21
to PDFTron SDK
Setting the scene:
I'm using a vanilla PTDocumentController to display PDF files.
In the upper right, I have the magnifying glass.  Tapping on it makes the search bar pop up from the bottom.
This is great, it's absolutely what I want.

Question:
How can I programmatically set the initial text that appears in that search bar?

We have our own search algorithm that presents a list of PDF documents that contain that search term.  So when the user opens up one of those docs, then taps on the magnifying glass, I want the search bar to start off showing that initial search term that led them to the doc in the first place.

Message has been deleted

Jamie Dassoulas

unread,
Feb 11, 2021, 8:33:27 PM2/11/21
to PDFTron SDK
Hello,

The recommended way to do this would be to subclass the PTTextSearchViewController class by following the instructions here:

Then in your subclass' viewDidAppear() method you could call the findText() API with your search string as the parameter:

class MyTextSearchViewController: PTTextSearchViewController {
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        findText("textToSearch")
    }
}

This will immediately perform the search with the specified text.

Please let us know how the above works for you and if you have any other questions. Thank you.

Randy Haid

unread,
Feb 11, 2021, 10:46:00 PM2/11/21
to PDFTron SDK
This is fantastic!  Works like a champ, thank you!
Reply all
Reply to author
Forward
0 new messages