# OcrResult

Artifact: [androidx.pdf:pdf-viewer](https://developer.android.com/jetpack/androidx/releases/pdf) [View Source](https://cs.android.com/search?q=file:androidx/pdf/ocr/OcrProvider.kt+class:androidx.pdf.ocr.OcrResult) Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

*** ** * ** ***


```
@ExperimentalPdfApi
public interface OcrResult
```

<br />

*** ** * ** ***

Represents the complete result of an OCR process, providing methods to query text spatially.

This interface manages the mapping between the raw recognized text and its visual coordinates in the original image.

## Summary

| ### Public methods |
|---|---|
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/pdf/ocr/OcrText` | `https://developer.android.com/reference/androidx/pdf/ocr/OcrResult#getAllText()()` Returns all recognized text and its corresponding bounding boxes. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Rect.html>>` | `@https://developer.android.com/reference/androidx/annotation/WorkerThread https://developer.android.com/reference/androidx/pdf/ocr/OcrResult#getSearchBounds(kotlin.String,kotlin.Boolean)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html searchTerm, boolean ignoreCase)` Searches for occurrences of the `https://developer.android.com/reference/androidx/pdf/ocr/OcrResult#getSearchBounds(kotlin.String,kotlin.Boolean)` and returns their bounding boxes. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/pdf/ocr/OcrText` | `https://developer.android.com/reference/androidx/pdf/ocr/OcrResult#getText(kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int)(int startX, int startY, int endX, int endY)` Returns the text and its bounding boxes within the selection range defined by two points. |
| `abstract https://developer.android.com/reference/androidx/pdf/ocr/OcrText` | `https://developer.android.com/reference/androidx/pdf/ocr/OcrResult#getWordAt(kotlin.Int,kotlin.Int)(int x, int y)` Returns the word and its bounding boxes at the specified coordinate. |

## Public methods

### getAllText

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
abstract @NonNull OcrText getAllText()
```

Returns all recognized text and its corresponding bounding boxes.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/pdf/ocr/OcrText` | An `https://developer.android.com/reference/androidx/pdf/ocr/OcrText` object containing all recognized text in the image. |

### getSearchBounds

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
@WorkerThread
abstract @NonNull List<@NonNull List<@NonNull Rect>> getSearchBounds(@NonNull String searchTerm, boolean ignoreCase)
```

Searches for occurrences of the `https://developer.android.com/reference/androidx/pdf/ocr/OcrResult#getSearchBounds(kotlin.String,kotlin.Boolean)` and returns their bounding boxes.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html searchTerm` | The string to search for. |
| `boolean ignoreCase` | `true` to ignore case when searching, `false` otherwise. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Rect.html>>` | A list of lists of `https://developer.android.com/reference/android/graphics/Rect.html` objects, where each inner list represents the visual bounding boxes for one occurrence of the search term. |

### getText

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
abstract @NonNull OcrText getText(int startX, int startY, int endX, int endY)
```

Returns the text and its bounding boxes within the selection range defined by two points.

The selection range is determined by finding the closest characters to the provided start and end coordinates.

| Parameters |
|---|---|
| `int startX` | The starting X coordinate, relative to image dimensions. |
| `int startY` | The starting Y coordinate, relative to image dimensions. |
| `int endX` | The ending X coordinate, relative to image dimensions. |
| `int endY` | The ending Y coordinate, relative to image dimensions. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/pdf/ocr/OcrText` | An `https://developer.android.com/reference/androidx/pdf/ocr/OcrText` object containing the selected text and its bounds. |

### getWordAt

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
abstract OcrText getWordAt(int x, int y)
```

Returns the word and its bounding boxes at the specified coordinate.

If the (`https://developer.android.com/reference/androidx/pdf/ocr/OcrResult#getWordAt(kotlin.Int,kotlin.Int)`, `https://developer.android.com/reference/androidx/pdf/ocr/OcrResult#getWordAt(kotlin.Int,kotlin.Int)`) coordinate lies within a word, that entire word is returned. If the point is on whitespace or outside any recognized text, `null` is returned.

| Parameters |
|---|---|
| `int x` | The X coordinate to query, relative to image dimensions. |
| `int y` | The Y coordinate to query, relative to image dimensions. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/pdf/ocr/OcrText` | An `https://developer.android.com/reference/androidx/pdf/ocr/OcrText` object containing the word at the point, or `null` if no word is found. |