Skip to content

Commit 9d2e28e

Browse files
991918: Redaction Annotation in JavaScript ES6 Part 1
1 parent bbc8c44 commit 9d2e28e

21 files changed

+477
-0
lines changed

Document-Processing/PDF/PDF-Viewer/javascript-es6/Redaction/events.md

Whitespace-only changes.

Document-Processing/PDF/PDF-Viewer/javascript-es6/Redaction/mobile-view.md

Whitespace-only changes.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
layout: post
3+
title: Redaction annotation in Typescript PDF Viewer | Syncfusion
4+
description: Learn how to hide sensitive information with interactive and programmatic redaction using the Syncfusion JavaScript PDF Viewer.
5+
platform: document-processing
6+
control: PDF Viewer
7+
documentation: ug
8+
domainurl: ##DomainURL##
9+
---
10+
11+
# Redaction in JavaScript (ES6) PdfViewer
12+
13+
Redaction annotations are used to hide confidential or sensitive information in a PDF. The Syncfusion JavaScript PDF Viewer (EJ2) lets you mark areas or entire pages for redaction, customize their appearance, and permanently apply them with a single action.
14+
15+
N> Prerequisites: Add the PdfViewer control to your JavaScript application and ensure the redaction feature is available in the version you are using. Once applied, redaction permanently removes the selected content.
16+
17+
![Toolbar with the Redaction tool highlighted](redaction-annotations-images/redaction-icon-toolbar.png)
18+
19+
## Add Redaction Annotations
20+
21+
You can mark specific content for redaction using the toolbar or through code.
22+
23+
Select the **Redaction tool** and draw over the text or graphics you want to hide. You can also add overlay text (such as “Confidential”) and adjust the style — fill color, border color, and opacity.
24+
25+
![Drawing a redaction region over page content](redaction-annotations-images/adding-redaction-annotation.png)
26+
27+
## Delete Redaction Annotations
28+
29+
Redaction annotations can be removed easily:
30+
31+
- Click the **Delete** button on the toolbar, or
32+
- Select the annotation and press the **Delete** key.
33+
34+
![Toolbar showing the Delete command for redaction](redaction-annotations-images/redaction-delete-icon.png)
35+
36+
## Redact Entire Pages
37+
38+
The viewer allows you to redact whole pages that contain sensitive information. You can choose specific pages, page ranges, or redact all pages using the built‑in dialog, or perform the same action programmatically.
39+
40+
![Toolbar showing the Redact Page option](redaction-annotations-images/redact-page-icon.png)
41+
42+
## Apply Redaction
43+
44+
Once annotations are added, you can permanently apply them to the document. This action cannot be undone.
45+
46+
Use the **Apply Redaction** button on the toolbar or call the API method:
47+
48+
- The button is disabled until at least one redaction annotation exists.
49+
- It becomes active when redaction annotations are present.
50+
51+
![Toolbar showing the Apply Redaction button](redaction-annotations-images/redact-button-icon.png)
52+
53+
A confirmation dialog appears before applying redaction to ensure you acknowledge the irreversible nature of the process.
54+
55+
![Confirmation dialog for applying redaction](redaction-annotations-images/apply-redaction-dialog.png)
56+
57+
N> After redaction is applied, the original content cannot be recovered.
58+
59+
## Comment Support
60+
61+
Redaction annotations can include comments using the built‑in comment panel. This helps you add notes, track reviews, or record the reason for redaction.
62+
63+
Comments can be added through the UI or API. For more details, see the [Comments documentation](../annotations/comments).
64+
65+
## Import and Export Redaction Annotations
66+
67+
You can save and reload redaction annotations by exporting and importing them in JSON format. This makes it easy to persist annotations or share them across sessions.
68+
69+
For more details, see the [Export and import annotations documentation](../how-to/import-export-annotation-ts).
70+
71+
## See also
72+
73+
* [UI interactions](./ui-interaction)
74+
* [Programmatic support](./programmatic-support)
75+
* [Toolbar items](./toolbar)
76+
* [Mobile view](./mobile-view)
77+
* [Events](./events)
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
layout: post
3+
title: Programmatic support for redaction in JavaScript PDF Viewer | Syncfusion
4+
description: Learn how to add, delete, update, and apply redaction annotations programmatically in the Syncfusion JavaScript (ES6/TypeScript) PDF Viewer.
5+
platform: document-processing
6+
control: PdfViewer
7+
documentation: ug
8+
---
9+
10+
# Programmatic support for redaction in JavaScript (ES6) PdfViewer
11+
12+
The Syncfusion JavaScript PDF Viewer (EJ2) provides APIs to add, update, delete, and apply redaction annotations programmatically. You can also redact entire pages, configure default properties, and work with the redaction property panel.
13+
14+
## Add redaction annotations programmatically
15+
16+
You can add redaction annotations to a PDF document using the `addAnnotation` method of the `annotation` module.
17+
18+
```html
19+
20+
```
21+
22+
```ts
23+
document.getElementById('addRedactAnnot').addEventListener('click', () => {
24+
viewer.annotation.addAnnotation("Redaction", {
25+
bound: { x: 200, y: 480, width: 150, height: 75 },
26+
pageNumber: 1,
27+
markerFillColor: '#0000FF',
28+
markerBorderColor: 'white',
29+
fillColor: 'red',
30+
overlayText: 'Confidential',
31+
fontColor: 'yellow',
32+
fontFamily: 'Times New Roman',
33+
fontSize: 8,
34+
beforeRedactionsApplied: false
35+
});
36+
});
37+
```
38+
39+
You can listen to the `annotationAdd` event to track when annotations are added:
40+
41+
```ts
42+
viewer.annotationAdd = (args) => {
43+
console.log('Annotation added:', args);
44+
};
45+
```
46+
47+
## Delete redaction annotations programmatically
48+
49+
Redaction annotations can be removed using the `deleteAnnotationById` event or by selecting and deleting them through code.
50+
51+
```html
52+
<button id="deleteAnnotationbyId">Delete Annotation By Id</button>
53+
```
54+
```ts
55+
// Delete annotation by id
56+
document.getElementById('deleteAnnotationbyId').addEventListener('click', () => {
57+
viewer.annotationModule.deleteAnnotationById(
58+
viewer.annotationCollection[0].annotationId
59+
);
60+
});
61+
```
62+
63+
Alternatively, you can remove annotations by selecting them in the UI and pressing the **Delete** key.
64+
65+
## Update redaction annotation properties programmatically
66+
67+
You can update properties of an existing redaction annotation using the `editAnnotation` API. For example, to change overlay text or fill color:
68+
69+
```html
70+
<button id="editRedactAnnotation">Edit Redact Annotation</button>
71+
```
72+
```ts
73+
let editRedactAnnotation = document.getElementById('editRedactAnnotation');
74+
if (editRedactAnnotation) {
75+
editRedactAnnotation.addEventListener('click', function () {
76+
if (viewer) {
77+
for (let i = 0; i < viewer.annotationCollection.length; i++) {
78+
if (viewer.annotationCollection[i].subject === "Redaction") {
79+
viewer.annotationCollection[i].overlayText= 'EditedAnnotation',
80+
viewer.annotationCollection[i].markerFillColor= '#22FF00',
81+
viewer.annotationCollection[i].markerBorderColor= '#000000',
82+
viewer.annotationCollection[i].isRepeat= true,
83+
viewer.annotationCollection[i].fillColor= '#F8F8F8',
84+
viewer.annotationCollection[i].fontColor= '#333333',
85+
viewer.annotationCollection[i].fontSize= 14,
86+
viewer.annotationCollection[i].fontFamily= 'Symbol',
87+
viewer.annotationCollection[i].textAlign= 'Right'
88+
viewer.annotationCollection[i].beforeRedactionsApplied= false
89+
viewer.annotation.editAnnotation(viewer.annotationCollection[i]);
90+
}
91+
}
92+
}
93+
});
94+
}
95+
```
96+
97+
## Add page redactions programmatically
98+
99+
Entire pages can be marked for redaction using the `addPageRedactions` method:
100+
101+
```html
102+
<button id="addPageRedactions">Add Page Redaction</button>
103+
```
104+
```ts
105+
document.getElementById('addPageRedactions').addEventListener('click', () => {
106+
viewer.annotation.addPageRedactions([1, 3, 5, 7]); // Redacts pages 1, 3, 5, and 7
107+
});
108+
```
109+
110+
## Apply redaction programmatically
111+
112+
Once annotations are added, you can permanently apply them to the document using the `redact` method:
113+
114+
```html
115+
<button id="redact">Apply Redaction</button>
116+
```
117+
```ts
118+
document.getElementById('redact').addEventListener('click', () => {
119+
viewer.annotation.redact();
120+
});
121+
```
122+
123+
N> Applying redaction is irreversible. Once applied, the original content cannot be recovered.
124+
125+
## Configure default redaction annotation properties
126+
127+
You can configure default properties for redaction annotations (such as fill color, overlay text, and font) when adding them programmatically:
128+
129+
```ts
130+
viewer.redactionSettings= {
131+
overlayText: 'Confidential',
132+
markerFillColor: '#FF0000',
133+
markerBorderColor: '#000000',
134+
isRepeat: false,
135+
fillColor: '#F8F8F8',
136+
fontColor: '#333333',
137+
fontSize: 14,
138+
fontFamily: 'Symbol',
139+
textAlign: 'Right'
140+
};
141+
```
142+
143+
## Redaction property panel
144+
145+
The redaction property panel allows users to update annotation properties through the UI. Programmatically, you can invoke the property panel by selecting an annotation and calling the relevant APIs. Properties such as overlay text, font style, and fill color can be updated directly in the panel.
146+
147+
![Redaction Property Panel](../redaction/redaction-annotations-images/redaction-property-panel-icon.png)
148+
149+
## See also
150+
151+
* [Overview of Redaction](./overview)
152+
* [Redaction UI interactions](./ui-interaction)
153+
* [Programmatic support](./programmatic-support)
154+
* [Redaction Toolbar](./toolbar)
155+
* [Reaction in Mobile view](./mobile-view)
156+
* [Events](./events)
198 KB
Loading
141 KB
Loading
239 KB
Loading
138 KB
Loading
195 KB
Loading
227 KB
Loading

0 commit comments

Comments
 (0)