Skip to content
Guides

Find and Replace in Content Editing Mode

In content editing mode, when users perform text searches and replacements in a PDF document, the search results are typically highlighted, providing links for navigation to the corresponding positions. Users can also replace individual keywords or all occurrences of a keyword with the provided text. By leveraging the search and replace features provided by the ComPDFKit SDK, you can easily implement these functionalities.

Text Search

In content editing mode, text search allows users to input keywords to search for matching text throughout the entire PDF document. It also enables text replacement for individual or all occurrences of keywords.

swift
let results = document?.startFindEditText(from: page, with: "searchText", options:.caseSensitive)
objective-c
NSArray *results = [documet startFindEditTextFromPage:page withString:@"searchText" options:CPDFSearchCaseSensitive];

Single Replacement

Replace the text for a single keyword.

swift
let currentSelection: CPDFSelection
document?.replace(with: currentSelection, search: "searchText", toReplace: "replaceText")
objective-c
CPDFSelection *currentSelection;
  [documet replaceWithSelection:currentSelection searchString:@"searchText"  toReplaceString:@"replaceText" completionHandler:nil];

Replace All

Replace the text for all occurrences of a keyword.

swift
document?.replaceAllEditText(with:"searchText", toReplace: "replaceText")
objective-c
[documet replaceAllEditTextWithString:@"searchText" toReplaceString:@"replaceText"];