Repository navigation
Expand file tree
/
Copy path19_ocr.py
More file actions
52 lines (40 loc) · 1.41 KB
/
Copy path19_ocr.py
File metadata and controls
52 lines (40 loc) · 1.41 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
"""
19 - OCR for scanned PDFs (Windows wheels only).
- make_searchable_pdf: add an invisible text layer to scanned pages
- redact_scanned_pdf: find terms via OCR and redact them
On Linux/macOS this script catches OcrNotSupportedError and exits cleanly.
Run:
python examples/19_ocr.py
"""
from _common import (
header, info, success, warn, ensure_output_dir, get_sample_pdf, init_license,
)
import exis_pdfeditor
from exis_pdfeditor import OcrNotSupportedError
def main() -> None:
init_license()
header("Demo 19 - OCR (Windows only)")
sample = get_sample_pdf()
out = ensure_output_dir()
try:
info("make_searchable_pdf...")
result = exis_pdfeditor.make_searchable_pdf(
str(sample),
str(out / "19-searchable.pdf"),
languages=["eng"],
dpi=300,
)
success(f"make_searchable_pdf -> {result}")
info("redact_scanned_pdf (sample terms)...")
result = exis_pdfeditor.redact_scanned_pdf(
str(sample),
str(out / "19-redact-scanned.pdf"),
terms=["CONFIDENTIAL", "SSN"],
visible_replacement="[REDACTED]",
)
success(f"redact_scanned_pdf -> {result}")
except OcrNotSupportedError as ex:
warn(f"OCR not available on this platform/wheel: {ex}")
info("Install the Windows wheel to exercise OCR demos.")
if __name__ == "__main__":
main()