Reference
TextRedactor
¶
Redact a text from a pdf file
Methods:
-
redact_text(file_path: Path, text_to_redact: str, output_file_name:Path) -> bool
-
redact_all_files_in_dir(base_path: Path, text_to_redact: str, output_file_suffix: str) -> None
Source code in redact_pdf/redact.py
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
redact_all_files_in_dir(base_path, text_to_redact, output_file_suffix)
¶
Redact all files in a local directory
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
Path
|
Base directory to find all *.pdf files (recursively) |
required |
text_to_redact
|
str
|
Text or phrase to be redacted in every page of pdf file. |
required |
output_file_suffix
|
Path
|
Suffix to append to original file name to be saved. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
>>> from redact_pdf.redact import TextRedactor
>>> tr = TextRedactor()
>>> base_path = Path("path/to/files/")
>>> TEXT_TO_REDACT = "Confidential"
>>> suffix = "redacted"
>>> tr.redact_all_files_in_dir(base_path=base_path, text_to_redact=TEXT_TO_REDACT, output_file_suffix=suffix)
Source code in redact_pdf/redact.py
redact_text(file_path, text_to_redact, output_file_name)
¶
Open the document and redact the text
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
PDF file path. |
required |
text_to_redact
|
str
|
Text or phrase to be redacted in every page of pdf file. |
required |
output_file_name
|
Path
|
PDF file name (include .pdf) to be saved after redact. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
If successfully redacts the text in pdf |
Examples:
>>> from redact_pdf.redact import TextRedactor
>>> tr = TextRedactor()
>>> pdf_file = Path("path/to/input.pdf")
>>> TEXT_TO_REDACT = "Confidential"
>>> save_path = Path("path/to/output.pdf")
>>> tr.redact_text(file_path=pdf_file, text_to_redact=TEXT_TO_REDACT, output_file_name=save_path)