---
title: "Search & redact PDF on iOS | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/ios/redaction/search-and-redact/"
md_url: "https://www.nutrient.io/guides/ios/redaction/search-and-redact.md"
last_updated: "2026-05-14T21:57:26.904Z"
description: "Nutrient enables you to search and redact text in a PDF document. In this guide, you’ll see how to redact a search term in a document."
---

# Search and redact PDFs on iOS

Nutrient enables you to search and redact text in a PDF document. In this guide, you’ll see how to redact a search term in a document.

First, you’ll have to loop through all the pages in the document to find the search term and mark the matching strings for redaction. To get the text in the document, you’ll need to use [`TextParser`](https://www.nutrient.io/api/ios/documentation/pspdfkit/textparser), which you can access via the [`Document`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document)’s [`textParserForPage(at:)`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document/textparserforpage(at:)) method:

```swift

let fileURL = Bundle.main.url(forResource: "Document", withExtension: "pdf")!
let document = Document(url: fileURL)

let wordToRedact = "Personal"

for pageIndex in 0..<document.pageCount {
    if let textParser = document.textParserForPage(at: pageIndex) {
        textParser.words.forEach { word in
        // Redact all the words that contain the search term.
        if word.stringValue.range(of: wordToRedact!)!= nil {
            // Create a redaction annotation for each URL and add it to the document.
            let redactionRect = word.frame
            let redaction = RedactionAnnotation()
            redaction.boundingBox = redactionRect
            redaction.rects = [redactionRect]
            redaction.color =.orange
            redaction.fillColor =.black
            redaction.overlayText = "REDACTED"
            redaction.pageIndex = pageIndex
            document.add(annotations: [redaction])
        }
    }
}

```

And finally, create a new PDF file for the redacted document by applying redactions using the [`Processor`](https://www.nutrient.io/api/ios/documentation/pspdfkit/processor) API, instantiate a [`Document`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document) object, and present it in a [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller), like so:

```swift

// Use Processor to create the newly redacted document.
let processorConfiguration = Processor.Configuration(document: document)!

// Apply redactions to permanently redact URLs from the document.
processorConfiguration.applyRedactions()

let processor = Processor(configuration: processorConfiguration, securityOptions: nil)
try? processor.write(toFileURL: redactedDocumentURL)

// Instantiate the redacted document and present it.
let redactedDocument = Document(url: redactedDocumentURL)
let pdfController = PDFViewController(document: redactedDocument)
present(UINavigationController(rootViewController: pdfController), animated: true)

```





For more details about redacting a document using regular expressions, refer to [`SearchAndRedactTextExample.swift`](https://github.com/PSPDFKit/pspdfkit-ios-catalog/blob/master/Catalog/Examples/DocumentProcessing/SearchAndRedactTextExample.swift) in the [Nutrient Catalog](https://github.com/PSPDFKit/pspdfkit-ios-catalog) app.
---

## Related pages

- [PDF redaction library for iOS](/guides/ios/redaction.md)
- [Redacting PDFs programmatically on iOS](/guides/ios/features/redaction.md)
- [Redacting PDFs in iOS viewer](/guides/ios/redaction/built-in-ui.md)
- [Redact PDFs with Nutrient iOS SDK](/guides/ios/redaction/introduction-to-redaction.md)
- [Using RegEx to redact PDFs on iOS](/guides/ios/redaction/regex-patterns.md)

