Component Search

Table of Contents

About the Search Highlight Example

The Search example demonstrates how the Search Controller API can be used to search for text in a PDF document. Text that has been found is drawn in a highlighted state to easily identify the results. Search criteria can also be set for case-sensitive and whole word searches.

The following code snippet shows how to add search terms tot he searchController and then iterate over any hits.

The source-code for this example is located at:

A primer on using Maven or Gradle build commands can be found here (Maven) and here (Gradle)

DocumentSearchController searchController =
        controller.getDocumentSearchController();
// add a specified search terms.
for (String term : terms) {
    searchController.addSearchTerm(term, false, false);
}
// search the pages in the document or a subset
Document document = controller.getDocument();
// list of founds words to print out
ArrayList<WordText> foundWords;
for (int pageIndex = 0; pageIndex < document.getNumberOfPages();
     pageIndex++) {
    foundWords = searchController.searchPage(pageIndex);
    System.out.println("Page " + pageIndex);
    if (foundWords != null){
        for (WordText wordText : foundWords){
            System.out.println("    found hit: " + wordText.toString());
        }
    }
}
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2017 ICEsoft Technologies Canada Corp.