On this page
Guides
Find and Replace in Content Editing Mode
In content editing mode, when users perform text search and replace in a PDF document, the search results are typically highlighted, providing links for navigation to the corresponding locations. Users can also replace text for individual keywords or all keywords. With the search and replace functionality provided by the ComPDFKit SDK, you can easily implement these features.
Text Search
In content editing mode, text search allows users to input keywords throughout the entire PDF document, find matching text, and replace text for individual or all keywords.
java
CPDFEditTextSearchReplace editTextSearchReplace = readerView.getEditTextSearchReplace();
// keywords: the search keywords
// options: search options, 0: case-insensitive, 1: case-sensitive, 2: match whole word
editTextSearchReplace.setSearchConfig(String keywords, int options);
// Highlight search results and return the result collection
SparseArray<ArrayList<CPDFEditFindSelection>> results = editTextSearchReplace.findSelections();
kotlin
val editTextSearchReplace = readerView.getEditTextSearchReplace()
// keywords: the search keywords
// options: search options, 0: case-insensitive, 1: case-sensitive, 2: match whole word
editTextSearchReplace.setSearchConfig(keywords : String, options : Int)
// Highlight search results and return the result collection
val results : SparseArray<ArrayList<CPDFEditFindSelection>> = editTextSearchReplace.findSelections()
Single Replacement
Replace the text for a single keyword.
java
CPDFEditTextSearchReplace editTextSearchReplace = readerView.getEditTextSearchReplace();
// Select the specified keyword
editTextSearchReplace.setCurrentSelection(page, textRangeIndex);
// Replace the text content
editTextSearchReplace.replace(String str);
readerView.invalidateChildrenAp();
kotlin
val editTextSearchReplace = readerView.getEditTextSearchReplace()
// Select the specified keyword
editTextSearchReplace.setCurrentSelection(page, textRangeIndex)
// Replace the text content
editTextSearchReplace.replace(String str)
readerView.invalidateChildrenAp()
Replace All
Replace the text for all keywords.
java
CPDFEditTextSearchReplace editTextSearchReplace = readerView.getEditTextSearchReplace();
editTextSearchReplace.replaceAll(replaceValue);
editTextSearchReplace.clear();
readerView.invalidateChildrenAp();
kotlin
val editTextSearchReplace = readerView.getEditTextSearchReplace()
editTextSearchReplace.replaceAll(replaceValue)
editTextSearchReplace.clear()
readerView.invalidateChildrenAp()