-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_redaction.py
More file actions
63 lines (50 loc) · 1.68 KB
/
Copy path06_redaction.py
File metadata and controls
63 lines (50 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
06 - Redaction.
Three redaction modes:
- Text-based (literal string match)
- Regex (e.g. SSN patterns)
- Area-based (rectangle on a specific page)
Redaction is destructive - the underlying text is removed from the content
stream, not just visually masked. This makes it suitable for HIPAA, GDPR,
and similar compliance requirements.
Run:
python examples/06_redaction.py
"""
from _common import (
header, info, success, ensure_output_dir, get_sample_pdf, init_license,
)
import exis_pdfeditor
def main() -> None:
init_license()
header("Demo 06 - Redaction")
sample = get_sample_pdf()
out = ensure_output_dir()
# Text + regex redaction
info("Text + regex redaction...")
result = exis_pdfeditor.redact(
str(sample),
str(out / "06-text-redacted.pdf"),
redactions=[
{"text": "the", "replaceWith": "[X]", "caseSensitive": False},
{"text": r"\d{3}-\d{2}-\d{4}", "isRegex": True, "replaceWith": "[SSN]"},
{"text": r"[\w\.-]+@[\w\.-]+\.\w+", "isRegex": True, "replaceWith": "[EMAIL]"},
],
)
success(f"Applied {result.redactionsApplied} redaction(s)")
# Area-based: black out a 200x20pt rectangle on page 1
info("Area-based redaction (rectangle on page 1)...")
area_result = exis_pdfeditor.redact(
str(sample),
str(out / "06-area-redacted.pdf"),
redactions=[
{
"area": {"x": 100, "y": 700, "width": 200, "height": 20},
"pageNumber": 1,
},
],
)
success(f"Area redactions applied: {area_result.redactionsApplied}")
print()
info(f"Output: {out}")
if __name__ == "__main__":
main()