---
title: "Search and redact PDF on Android | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/android/redaction/search-and-redact/"
md_url: "https://www.nutrient.io/guides/android/redaction/search-and-redact.md"
last_updated: "2026-06-05T20:16:40.058Z"
description: "Nutrient Android SDK 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 Android

Nutrient Android SDK 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.

The process involves using the [`TextSearch`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.search/-text-search/index.html) API and then looping through the search results, adding [`RedactionAnnotation`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.annotations/-redaction-annotation/index.html)s as you loop:

### KOTLIN

```kotlin

val wordToSearch = "secret"
val textSearch = TextSearch(document, configuration)
val searchResults = textSearch.performSearch(wordToSearch)

for (searchResult in searchResults) {
    val redaction = RedactionAnnotation(searchResult.pageIndex, searchResult.textBlock.pageRects).apply {
        color = Color.BLACK
        fillColor = Color.BLACK
        outlineColor = Color.YELLOW
        overlayText = "REDACTED"
    }
    document.annotationProvider.addAnnotationToPage(redaction)
}

```

### JAVA

```java

final String wordToSearch = "secret";
final TextSearch textSearch = new TextSearch(document, configuration);
final List<SearchResult> searchResults = textSearch.performSearch(wordToSearch);

for (SearchResult searchResult : searchResults) {
    final RedactionAnnotation redaction = new RedactionAnnotation(searchResult.pageIndex, searchResult.textBlock.pageRects);
    redaction.setColor(Color.BLACK);
    redaction.setFillColor(Color.BLACK);
    redaction.setOutlineColor(Color.YELLOW);
    redaction.setOverlayText("REDACTED");

    document.getAnnotationProvider().addAnnotationToPage(redaction);
}

```

Finally, create a new PDF file for the redacted document by applying redactions.

You can do so using the [`PdfProcessor`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-pdf-processor/index.html) API:

### KOTLIN

```kotlin

val outputFile: File
val document: PdfDocument
val processorTask = PdfProcessorTask.fromDocument(document).applyRedactions()

PdfProcessor.processDocument(processorTask, outputFile)
val redactedDocument = PdfDocumentLoader.openDocument(context, Uri.fromFile(outputFile))

```

### JAVA

```java

final File outputFile;
final PdfDocument document;
final PdfProcessorTask processorTask = PdfProcessorTask.fromDocument(document).applyRedactions();

PdfProcessor.processDocument(processorTask, outputFile);
final PdfDocument redactedDocument = PdfDocumentLoader.openDocument(context, Uri.fromFile(outputFile));

```

Or, you can use the [`DocumentSaveOptions#setApplyRedactions()`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document/-document-save-options/set-apply-redactions.html) option when saving the document via any of the save methods on `PdfDocument`.

Bear in mind that this will overwrite the existing document, removing content irreversibly:

### KOTLIN

```kotlin

val documentSaveOptions = DocumentSaveOptions(null, null, true, null);
documentSaveOptions.setApplyRedactions(true)
document.saveIfModified(documentSaveOptions)

```

### JAVA

```java

final DocumentSaveOptions documentSaveOptions = new DocumentSaveOptions(null, null, false, null);
documentSaveOptions.setApplyRedactions(true);
document.saveIfModified(documentSaveOptions);

```
---

## Related pages

- [PDF redaction library for Android](/guides/android/redaction.md)
- [Master PDF redaction on Android devices](/guides/android/redaction/introduction-to-redaction.md)
- [Redacting PDFs in Android viewer](/guides/android/redaction/built-in-ui.md)
- [Redacting PDFs programmatically on Android](/guides/android/features/redaction.md)
- [Using RegEx to redact PDFs on Android](/guides/android/redaction/regex-patterns.md)

