Skip to content

Commit 42dd655

Browse files
committed
feat: add overlay redaction example
1 parent aacea16 commit 42dd655

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { RedactionAnnotation, TextLine } from "@nutrient-sdk/viewer";
2+
import { baseOptions } from "../../shared/base-options";
3+
4+
const REDACTION_CONFIG = {
5+
color: window.NutrientViewer.Color.RED,
6+
overlayText: "REDACTED",
7+
};
8+
9+
function createRedactionFromTextLine(textLine: TextLine) {
10+
const { boundingBox, pageIndex } = textLine;
11+
12+
return new window.NutrientViewer.Annotations.RedactionAnnotation({
13+
id: window.NutrientViewer.generateInstantId(),
14+
pageIndex,
15+
boundingBox,
16+
rects: window.NutrientViewer.Immutable.List([boundingBox]),
17+
...REDACTION_CONFIG,
18+
});
19+
}
20+
21+
window.NutrientViewer.load({
22+
...baseOptions,
23+
theme: window.NutrientViewer.Theme.DARK,
24+
}).then(async (instance) => {
25+
const pageIndices = Array.from({ length: instance.totalPageCount });
26+
27+
const allPagesTextLines = await Promise.all(
28+
pageIndices.map((_, index) => instance.textLinesForPageIndex(index)),
29+
);
30+
31+
const redactionAnnotations = allPagesTextLines.flatMap((pageTextLines) =>
32+
pageTextLines.reduce<RedactionAnnotation[]>(
33+
(annotations, textLine) => [
34+
...annotations,
35+
createRedactionFromTextLine(textLine),
36+
],
37+
[],
38+
),
39+
);
40+
41+
await instance.create(redactionAnnotations);
42+
await instance.applyRedactions();
43+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: redaction
3+
title: Overlay Redactions on All Text
4+
description: Creates redactions with an overlay text for every text line in the document and applies them to fully redact all text content.
5+
keywords: [redaction, overlay, text-lines, full-document, batch-redaction]
6+
---

0 commit comments

Comments
 (0)