# pdf-viewer-redaction

> PDF viewer sample marking sensitive regions or searched text for permanent redaction.

**Framework:** vue  **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/vue/pdf-viewer-redaction.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-vue-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/PdfViewer.vue

```vue
<template>
  <div class="control-section redaction">
    <div class="controls" role="group" aria-label="Redaction controls">
      <button class="e-btn e-primary" type="button" :disabled="!loaded" @click="addRedaction">Add Redaction</button>
      <label for="redaction-search">Text to redact</label>
      <input id="redaction-search" v-model="searchText" class="e-input" type="search" :disabled="!loaded || searching" />
      <button class="e-btn" type="button" :disabled="!loaded || searching" @click="searchAndMark">{{ searching ? 'Searching...' : 'Search & Mark' }}</button>
      <button class="e-btn e-danger" type="button" :disabled="!loaded" @click="applyRedactions">Apply Redactions</button>
    </div>
    <p role="status">{{ statusMessage }}</p>
    <ejs-pdfviewer id="pdfviewer" ref="pdfviewer" :documentPath="documentPath" :resourceUrl="resourceUrl" :isExtractText="true" :toolbarSettings="toolbarSettings" :documentLoad="documentLoad" />
  </div>
</template>

<script lang="ts">
import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, Annotation, FormFields, FormDesigner, PageOrganizer } from '@syncfusion/ej2-vue-pdfviewer';

export default {
  components: { 'ejs-pdfviewer': PdfViewerComponent },
  data() {
    return {
      documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf',
      resourceUrl: 'https://cdn.syncfusion.com/ej2/35.1.37/dist/ej2-pdfviewer-lib',
      loaded: false, searching: false, searchText: '', statusMessage: 'Loading PDF document...',
      toolbarSettings: { showTooltip: true, toolbarItems: ['OpenOption', 'UndoRedoTool', 'PageNavigationTool', 'MagnificationTool', 'PanTool', 'SelectionTool', 'CommentTool', 'SubmitForm', 'AnnotationEditTool', 'RedactionEditTool', 'FormDesignerEditTool', 'SearchOption', 'PrintOption', 'DownloadOption'] }
    };
  },
  provide: { PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, Annotation, FormFields, FormDesigner, PageOrganizer] },
  methods: {
    documentLoad() {
      const viewer = (this.$refs.pdfviewer as any).ej2Instances;
      viewer.toolbar.showRedactionToolbar(true);
      this.loaded = true;
      this.statusMessage = 'Document loaded. Add a redaction or search for text to mark.';
    },
    addRedaction() {
      const viewer = (this.$refs.pdfviewer as any).ej2Instances;
      viewer.annotation.addAnnotation('Redaction', { bound: { x: 150, y: 400, width: 200, height: 40 }, pageNumber: viewer.currentPageNumber, overlayText: 'Confidential', fillColor: '#000000', fontColor: '#FFFFFF' });
      this.statusMessage = 'Redaction added. Apply Redactions to make it permanent.';
    },
    async searchAndMark() {
      const term = this.searchText.trim();
      if (!term) { this.statusMessage = 'Enter text to search for and redact.'; return; }
      this.searching = true;
      this.statusMessage = `Searching for "${term}"...`;
      try {
        const viewer = (this.$refs.pdfviewer as any).ej2Instances;
        const results = await viewer.textSearchModule.findTextAsync(term, false);
        let count = 0;
        results.forEach((result: any) => (result.bounds || []).forEach((bound: any) => {
          viewer.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' });
          count++;
        }));
        this.statusMessage = count ? `Marked ${count} match${count === 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.searching = false; }
    },
    applyRedactions() {
      if (!window.confirm('Applying redactions permanently removes the marked content. Continue?')) { this.statusMessage = 'Redaction application canceled.'; return; }
      (this.$refs.pdfviewer as any).ej2Instances.annotation.redact();
      this.statusMessage = 'Applying redactions. The viewer will reload when processing is complete.';
    }
  }
};
</script>

<style scoped>
.controls { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-bottom: 8px; }
.controls label { font-weight: 600; }
.controls input { width: 220px; }
#pdfviewer { height: 640px; }
</style>

```
