Skip to main content Skip to footer

Perform Advanced Searches in Web-Based PDF Documents

When working with digital documents, searching the document's content to find specific information is a common action. Different document viewers implement this feature in their own way. The searching operation can be a basic search finding the exact match of the search text, or it could be an advanced search where the search text is combined with various search criteria.

The GrapeCity Documents PDF Viewer is a Javascript-based viewer for viewing and editing PDF documents. It supports advanced search options to search text (or text-based) patterns in the PDF Viewer.

It supports six different search criteria including Match Case, Whole Word, Starts With, Ends With, Wildcards, and Proximity.

This post describes new advanced search features of the GrapeCity Documents PDF Viewer.

Search Panel

The search operation in GcPdfViewer is performed using the Search Panel, which is displayed by clicking on the second icon in the left panel of GcPdfViewer. It is one of the default panels and can be added to GcPdfViewer by invoking the AddDefaultPanels method of GcPdfViewer client-side API. In case you want to add only the search panel to GcPdfViewer, then you can accomplish the same by invoking the AddSearchPanel method. The code snippet below depicts invoking the AddDefaultPanels method:

<div id="host"></div>
<script>
    var viewer = new GcPdfViewer("#host");
    viewer.addDefaultPanels();   
    viewer.beforeUnloadConfirmation = true;   
</script>

The search panel consists of a textbox used to enter the search text followed by multiple checkboxes each used to enable or disable different search criteria and a search button to initiate the search operation. Here is a quick view of the Search Panel

Perform Advanced Searches in Web-Based PDF Documents

Search Results

The search panel also displays the search results below the search button. The search result displays the count of search text occurrences in the PDF document, along with an entry for each occurrence describing the page number on which it can be found. When you click on any search result, the viewer scrolls to the specific page and highlights the found search text.

Perform Advanced Searches in Web-Based PDF Documents

You can even highlight all the search results by checking the HighLight all checkbox in the search panel:

Perform Advanced Searches in Web-Based PDF Documents

The images above depict the default colors used to highlight the search results in the document content. These Highlight colors can be altered using the following code:

    var viewer = new GcPdfViewer("#host", {
        "useCanvasForSelection": {
            //Changes the default color used to highlight all the search results in document.
            inactiveHighlightColor: 'rgba(255,0,0, 0.5)',
            //Changes the default color used to highlight currently selected search result in document.
            highlightColor: 'rgba(0,255,0, 0.5)',                       
            //Changes the default color used to highlight the selected content in document.
            selectionColor: 'rgba(0,0,255,0.5)'
        }
    });  
    viewer.addDefaultPanels();  
</script>

Search Criteria

Match Case

The Match Case criteria perform case sensitive search, returning words that match each uppercase and lowercase character of the search text in the same order in a word. It can be combined with any other search criteria.

Example: Searching for text "Earth" returns Earth when Match Case is enabled, and returns Earth/earth when Match Case is disabled.

Perform Advanced Searches in Web-Based PDF Documents

Whole Word

The Whole word criteria finds the whole words in the document content which match the word specified in the search text. Hence, it cannot be combined with the Starts With and Ends With criteria.

Example: Searching for text "prevent" returns word prevent when Whole word criteria is enabled and returns words preventing/prevent when Whole word criteria is disabled.

Perform Advanced Searches in Web-Based PDF Documents

Starts With

The Starts with search criteria searches the document content for words starting with the character or word specified in the search text. It can be combined with the Match case and Ends with criteria.

Example: Searching for text "green" when Starts with criteria is enabled returns all words that start with green.

Perform Advanced Searches in Web-Based PDF Documents

Ends With

The Ends with search criteria searches the document content for words ending with the character or word specified in the search text. It can be combined with the Match case and Starts with criteria.

Example: Searching for text "ing" when Ends with criteria is enabled returns all words that end with ing.

Perform Advanced Searches in Web-Based PDF Documents

Wildcards

The Wildcards search criteria searches the document content by making use of the two wildcard characters -- Asterisk (*) and Question Mark (?).

The Asterisk character can be used to replace the occurrence of any number of characters anywhere in the word. While the Question Mark character can be used to replace the occurrence of one character occurring zero or one time in a word. It cannot be combined with Starts with, Ends with, Whole word, and Proximity search criteria.

Example: Searching for text "ed*" when Wildcards criteria is enabled returns all words containing ed preceded/succeeded by any numbers of characters such as related, swedish, reduction, etc.

Perform Advanced Searches in Web-Based PDF Documents

Example: Searching for text "t?e" when Wildcards criteria is enabled returns all words containing characters 't' and 'e' having zero or one character in between such as temperature, term, these, the, etc.

Perform Advanced Searches in Web-Based PDF Documents

Proximity

The Proximity search criteria searches the document content to find two or more words separated by a given number of words. The AROUND(N) operator is used to enter the search text and it specifies a number value which states the maximum number of words that can occur between the specified words. The search results includes only those words which have n or less than n number of words between them and are present on the same page of the document. It cannot be combined with Starts with, Ends with, and Wildcards search criteria.

Example: Searching for text "power AROUND(8) fossil" when Proximity criteria is enabled returns the words power and fossil which are at a gap of eight words.

Perform Advanced Searches in Web-Based PDF Documents

You can refer to our documentation for more details on the Advanced Search feature. Try these different searching criteria to narrow down or maximize the search results when trying to find specific information in a document.

Please let us know if you would like to have any other search criteria added to this list.

Happy Coding!

Manpreet Kaur - Senior Software Engineer

Manpreet Kaur

Senior Software Engineer
comments powered by Disqus