Batch protect, unlock, and permanently redact sensitive information from PDF documents.
pdf-redactor is a command-line tool for processing multiple PDF files at once. It can password-protect PDFs, remove password protection, redact literal text or regular expression matches, and generate an audit report of everything it processed.
It was built for repetitive workflows where many documents contain the same confidential information and need to be sanitized quickly.
Note
This tool works with text-based PDFs. Scanned PDFs are images and require OCR before they can be searched or redacted.
- Password-protect PDF documents
- Remove password protection
- Batch process entire folders
- Redact literal text
- Redact using regular expressions
- Built-in presets (email, PAN, phone numbers, URLs, Aadhaar, IPv4)
- Custom pattern files
- TOML configuration support
- Dry-run mode
- JSON audit reports
- Rich CLI progress bar
- Continue processing even if one file fails
- Preserve original files
Clone the repository:
git clone https://github.com/<your-username>/pdf-redactor.git
cd pdf-redactorCreate a virtual environment:
python -m venv .venv
.venv\Scripts\activatepython3 -m venv .venv
source .venv/bin/activateInstall the package:
pip install -e .Protect a PDF:
pdf-redactor protect document.pdf protected.pdfUnlock a PDF:
pdf-redactor unlock protected.pdf unlocked.pdfRedact every PDF inside a folder:
pdf-redactor redact input output \
--password 1234 \
--preset email \
--preset panpdf-redactor protect input.pdf protected.pdfpdf-redactor unlock protected.pdf unlocked.pdfpdf-redactor redact input output \
--password 1234 \
--match "John Doe"Multiple matches:
pdf-redactor redact input output \
--password 1234 \
--match "John Doe" \
--match "Confidential"pdf-redactor redact input output \
--password 1234 \
--regex "[A-Z]{5}[0-9]{4}[A-Z]"Multiple regex patterns are supported.
Instead of writing regex manually:
pdf-redactor redact input output \
--password 1234 \
--preset email \
--preset phone \
--preset panAvailable presets include:
- phone
- pan
- aadhaar
- ipv4
- url
patterns.txt
John Doe
Confidential
Internal Use Only
Run:
pdf-redactor redact input output \
--password 1234 \
--match-file patterns.txtcompany.toml
presets = [
"email",
"pan",
]
matches = [
"Confidential",
]
regexes = [
"\\b\\d{10}\\b",
]Run:
pdf-redactor redact input output \
--password 1234 \
--config company.tomlCommand-line arguments and configuration can be combined.
Preview what would be redacted without modifying any files.
pdf-redactor redact input output \
--password 1234 \
--preset email \
--dry-runGenerate a machine-readable report.
pdf-redactor redact input output \
--password 1234 \
--preset email \
--report report.jsonExample:
{
"summary": {
"tool_version": "1.0.0",
"generated_at": "2026-07-05T12:34:56+00:00",
"pdfs_scanned": 5,
"literal_hits": 8,
"regex_hits": 21,
"total_hits": 29,
"dry_run": false
},
"files": [
{
"name": "invoice.pdf",
"status": "success",
"literal_hits": 2,
"regex_hits": 5,
"total_hits": 7
}
]
}pdf-redactor/
├── src/
│ └── pdf_redactor/
│ ├── cli.py
│ ├── config.py
│ ├── console.py
│ ├── presets.py
│ ├── protect.py
│ ├── redactor.py
│ └── unlock.py
│
├── tests/
├── examples/
├── pyproject.toml
└── README.md
- Unlock the input PDF (if required).
- Search every page for literal and/or regex matches.
- Apply permanent PDF redactions.
- Save the processed document.
- Generate an optional JSON report.
- Works only with text-based PDFs.
- Does not perform OCR.
- Password-protected batch redaction assumes the input PDFs share the same password.
- Regex matches depend on the extracted text from the PDF.
Run the test suite:
pytestRun with coverage:
pytest --cov=pdf_redactorI had a folder full of password-protected PDFs that all contained the same sensitive information. Unlocking and redacting them one by one was repetitive, so I wrote a small tool to automate the process.
It grew from a simple script into a reusable command-line utility that others might find useful too.
MIT