> ## Documentation Index
> Fetch the complete documentation index at: https://webviewer-docs.mupdf.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Redaction API

The [`redaction`](#redaction) object is an instance accessible from the main [MuPDFWebViewer](/api-reference/introduction#initmupdfwebviewer) instance as follows:

```javascript theme={null}
const redaction = webViewer.redaction;
```

<Note>
  This assumes you have returned your instance name as `webViewer` from the [initMuPDFWebViewer()](/api-reference/introduction#initmupdfwebviewer) promise!
</Note>

## redaction

The `redaction` object has the following methods:

### get

```typescript theme={null}
get(config?: { textData: TextDataOption }): Promise<{ redactions: Annotation[] }>;
```

Returns an object containing (unapplied) redactions for the document.

#### Parameters

<ParamField body="config" type="object">
  Optional configuration. If omitted, returns all redactions for all pages.
</ParamField>

<Expandable title="config properties">
  <ParamField body="config.textData" type="webViewer.refs.redaction.textDataOption" required>
    The text data option for redactions. Required when `config` is provided.
  </ParamField>
</Expandable>

#### Returns

<ResponseField name="result" type="Promise<{ redactions: Annotation[] }>" required>
  A Promise that resolves to an object containing `redactions`.
</ResponseField>

**Example**

```javascript theme={null}
webViewer.redaction.get();
```

<Note>
  Note: if redactions have been previously applied then these redactions are permanent and, as we should expect, will **not be** returned!

  Use `result.redactions` to access the redaction array.
</Note>

### set

```typescript theme={null}
set(config: {
  redactions: {
    oid: number;
    pageIndex: number;
    name: string;
    rect?: TRect;
    opacity?: number;
    author?: string;
    canBePrinted?: boolean;
    locked?: boolean;
  }[];
}): Promise<undefined>;
```

Updates redactions.

#### Parameters

<ParamField body="config" type="object" required>
  The configuration object.
</ParamField>

<Expandable title="config properties">
  <ParamField body="config.redactions" type="object[]" required>
    An array where each item requires `oid`, `pageIndex`, and `name`.
  </ParamField>
</Expandable>

<Note>
  Use this method to update existing redactions by unique identifier.
</Note>

### add

```typescript theme={null}
add(config: {
  redactions: {
    oid?: number;
    pageIndex: number;
    name?: string;
    rect: TRect;
    opacity?: number;
    author?: string;
    canBePrinted?: boolean;
    locked?: boolean;
  }[];
}): Promise<{ redactions: Annotation[] }>;
```

Adds redactions.

#### Parameters

<ParamField body="config" type="object" required>
  The configuration object.
</ParamField>

<Expandable title="config properties">
  <ParamField body="config.redactions" type="object[]" required>
    An array where each item requires `pageIndex` and `rect`. `oid` and `name` are optional.
  </ParamField>
</Expandable>

### remove

```typescript theme={null}
remove(config: {
  redactions: {
    oid: number;
    name: string;
    pageIndex: number;
  }[];
}): Promise<undefined>;
```

Removes redactions.

#### Parameters

<ParamField body="config" type="object" required>
  The configuration object.
</ParamField>

<Expandable title="config properties">
  <ParamField body="config.redactions" type="object[]" required>
    An array where each item requires `oid`, `name`, and `pageIndex`.
  </ParamField>
</Expandable>

Each redaction item must include `oid`, `name`, and `pageIndex`. Matching redactions are removed.

### apply

```typescript theme={null}
apply(config: {
  redactions: {
    oid: number;
    name: string;
    pageIndex: number;
  }[];
}): Promise<undefined>;
```

Applies redactions.

#### Parameters

<ParamField body="config" type="object" required>
  The configuration object.
</ParamField>

<Expandable title="config properties">
  <ParamField body="config.redactions" type="object[]" required>
    An array where each item requires `oid`, `name`, and `pageIndex`.
  </ParamField>
</Expandable>

Each redaction item must include `oid`, `name`, and `pageIndex`. Matching redactions are applied.

## Redaction Types

The API uses different item shapes per method:

```typescript theme={null}
type SetRedaction = {
  oid: number;
  pageIndex: number;
  name: string;
  rect?: TRect;
  opacity?: number;
  author?: string;
  canBePrinted?: boolean;
  locked?: boolean;
};

type AddRedaction = {
  oid?: number;
  pageIndex: number;
  name?: string;
  rect: TRect;
  opacity?: number;
  author?: string;
  canBePrinted?: boolean;
  locked?: boolean;
};

type TargetRedaction = {
  oid: number;
  name: string;
  pageIndex: number;
};
```

### Supporting Types

```typescript theme={null}
export interface TRect {
  top: number;
  left: number;
  right: number;
  bottom: number;
}
```
