# pdf-viewer-redaction

> Search PDF text or place redaction marks, then apply them permanently to remove sensitive content.

**Framework:** angular  **Component:** PdfViewer  **Variant:** redaction

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/angular/pdf-viewer-redaction.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-angular-pdfviewer
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/pdf-viewer-redaction/pdf-viewer.component.html

```html
<div class="control-section">
    <div role="group" aria-label="Redaction controls"
        style="display:flex;align-items:flex-end;flex-wrap:wrap;gap:12px;margin-bottom:12px">
        <button class="e-btn e-primary" type="button" (click)="addRedaction()" [disabled]="!isDocumentLoaded">
            Add Redaction
        </button>
        <div style="width:220px">
            <label for="redaction-search-text" style="display:block;margin-bottom:4px">Text to redact</label>
            <input id="redaction-search-text" class="e-input" type="search" [value]="searchText"
                (input)="onSearchTextInput($event)" [disabled]="!isDocumentLoaded || isSearching">
        </div>
        <button class="e-btn" type="button" (click)="searchAndMarkRedactions()"
            [disabled]="!isDocumentLoaded || isSearching">
            {{ isSearching ? 'Searching...' : 'Search & Mark for Redaction' }}
        </button>
        <button class="e-btn e-danger" type="button" (click)="applyRedactions()" [disabled]="!isDocumentLoaded">
            Apply Redactions
        </button>
    </div>
    <p role="status">{{ statusMessage }}</p>
    <ejs-pdfviewer #pdfviewer id="redaction-viewer" [documentPath]="document" [resourceUrl]="resource"
        [isExtractText]="true"
        [toolbarSettings]="{ showTooltip: true, toolbarItems: ['OpenOption', 'UndoRedoTool', 'PageNavigationTool', 'MagnificationTool', 'PanTool', 'SelectionTool', 'CommentTool', 'SubmitForm', 'AnnotationEditTool', 'RedactionEditTool', 'FormDesignerEditTool', 'SearchOption', 'PrintOption', 'DownloadOption'] }"
        (documentLoad)="onDocumentLoad()" style="height:640px;display:block">
    </ejs-pdfviewer>
</div>

```

### src/components/pdf-viewer-redaction/pdf-viewer.component.ts

```typescript
import { Component, ViewChild } from '@angular/core';
import {
    AnnotationService,
    BookmarkViewService,
    FormDesignerService,
    FormFieldsService,
    LinkAnnotationService,
    MagnificationService,
    NavigationService,
    PageOrganizerService,
    PdfViewerComponent,
    PdfViewerModule,
    PrintService,
    RedactionSettings,
    TextSearchService,
    TextSelectionService,
    ThumbnailViewService,
    ToolbarService
} from '@syncfusion/ej2-angular-pdfviewer';

type AnnotationSettings = NonNullable<Parameters<PdfViewerComponent['annotation']['addAnnotation']>[1]>;

@Component({
    selector: 'control-content',
    templateUrl: 'pdf-viewer.component.html',
    providers: [
        LinkAnnotationService, BookmarkViewService, MagnificationService, ThumbnailViewService,
        ToolbarService, NavigationService, TextSearchService, TextSelectionService, PrintService,
        AnnotationService, FormFieldsService, FormDesignerService, PageOrganizerService
    ],
    standalone: true,
    imports: [PdfViewerModule]
})
export class RedactionComponent {
    @ViewChild('pdfviewer')
    public pdfviewerControl!: PdfViewerComponent;

    public readonly resource = 'https://cdn.syncfusion.com/ej2/35.1.37/dist/ej2-pdfviewer-lib';
    public readonly document = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
    public isDocumentLoaded = false;
    public searchText = '';
    public isSearching = false;
    public statusMessage = 'Loading PDF document...';
    private isApplyingRedactions = false;

    public onDocumentLoad(): void {
        this.pdfviewerControl.toolbar.showRedactionToolbar(true);
        this.isDocumentLoaded = true;
        if (this.isApplyingRedactions) {
            this.isApplyingRedactions = false;
            this.statusMessage = 'Redactions applied to the document.';
        } else {
            this.statusMessage = 'Document loaded. Add a redaction or search for text to mark.';
        }
    }

    public onSearchTextInput(event: Event): void {
        this.searchText = (event.currentTarget as HTMLInputElement).value;
    }

    public addRedaction(): void {
        this.pdfviewerControl.annotation.addAnnotation('Redaction', {
            bound: { x: 150, y: 400, width: 200, height: 40 },
            pageNumber: this.pdfviewerControl.currentPageNumber,
            overlayText: 'Confidential',
            fillColor: '#000000',
            fontColor: '#FFFFFF'
        } as RedactionSettings);
        this.statusMessage = 'Redaction added to the current page. Apply Redactions to make it permanent.';
    }

    public async searchAndMarkRedactions(): Promise<void> {
        const term = this.searchText.trim();
        if (!term) {
            this.statusMessage = 'Enter text to search for and redact.';
            return;
        }

        this.isSearching = true;
        this.statusMessage = `Searching for "${term}"...`;
        try {
            const results = await this.pdfviewerControl.textSearchModule.findTextAsync(term, false);
            let redactionCount = 0;

            for (const result of results) {
                if (typeof result.pageIndex !== 'number' || !result.bounds?.length) {
                    continue;
                }

                for (const bound of result.bounds) {
                    this.pdfviewerControl.annotation.addAnnotation('Redaction', {
                        bound: {
                            x: bound.x * (96 / 72),
                            y: bound.y * (96 / 72),
                            width: bound.width * (96 / 72),
                            height: bound.height * (96 / 72)
                        },
                        pageNumber: result.pageIndex + 1,
                        overlayText: 'Confidential',
                        fillColor: '#000000',
                        fontColor: '#FFFFFF'
                    } as AnnotationSettings);
                    redactionCount++;
                }
            }

            this.statusMessage = redactionCount
                ? `Marked ${redactionCount} match${redactionCount === 1 ? '' : 'es'} for "${term}". Apply Redactions to make them permanent.`
                : `No matches found for "${term}".`;
        } catch (error) {
            console.error('Unable to search the PDF for redaction text.', error);
            this.statusMessage = 'Unable to search the PDF. See the browser console for details.';
        } finally {
            this.isSearching = false;
        }
    }

    public applyRedactions(): void {
        if (!window.confirm('Applying redactions permanently removes the marked content. Continue?')) {
            this.statusMessage = 'Redaction application canceled.';
            return;
        }

        this.isApplyingRedactions = true;
        this.pdfviewerControl.annotation.redact();
        this.statusMessage = 'Applying redactions. The viewer will reload when processing is complete.';
    }
}

```
