pdfredact
Redact text in a PDF (true redaction, not just a visual overlay) using PyMuPDF. Finds occurrences of the specified text/pattern, applies a redaction annotation, and "burns" it into the page content, physically removing the underlying text (not recoverable via copy-paste or text extraction).
Installation
Requires Python 3.10 or later. The only dependency is PyMuPDF, which publishes prebuilt wheels for Linux, Windows, and macOS (no compiler required).
With pip
pip install .
or, for development (editable install with test dependencies):
pip install -e .[test]
With pipx (recommended for a command-line tool)
pipx installs the tool in an isolated virtual environment and
exposes only the pdfredact command on PATH, without touching the system Python.
Linux/macOS:
python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install . # run from the root of the repository
Windows:
On Windows it's convenient to install pipx via Scoop, which also
manages updating Python itself if needed:
# If Scoop isn't already installed:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
scoop install pipx
pipx ensurepath
Then, from the repository folder (in a new terminal, so ensurepath takes effect):
pipx install .
In both cases, after installation the pdfredact command is available directly in a new
terminal.
Usage
pdfredact input.pdf output.pdf -t "Mario Rossi" -t "CF: ABCDEF"
pdfredact input.pdf output.pdf -r "\bMCNP-\d{4}\b"
pdfredact input.pdf output.pdf -t "Confidential" --case-sensitive
pdfredact input.pdf output.pdf -t "foo" --pages 1,2,5-7
pdfredact input.pdf output.pdf --box "1:56,700,300,730"
pdfredact input.pdf output.pdf -t "foo" --fill-color "#ff0000"
Equivalent without installing, from the root of the repository:
python -m pdfredact input.pdf output.pdf -t "Mario Rossi"
Rectangle coordinates (--box)
Format: PAGE:x0,y0,x1,y1
PAGEis 1-based (page 1 = first page)x0,y0,x1,y1in PDF points (72 pt = 1 inch), origin at the top-left (same coordinate system returned bypage.search_for())- Corner order doesn't matter: the rectangle is normalized.
Exit codes
0 = success, 2 = input/usage error.
Known limitations
- Document metadata (Author, Title, XMP) and annotation/comment content are not handled,
since they don't appear in
get_text(). - A term split across multiple lines in the PDF layout might not be found.
- Scanned PDFs (image-only, with no extractable text) require OCR upstream: the tool finds nothing to redact in that case.
Always verify the output with pdftotext and pdfinfo -meta before distribution.
Windows compatibility
The project is tested in CI on Linux, Windows, and macOS (see .github/workflows/tests.yml)
and is compatible with Windows without modifications: it only uses os.path (no hardcoded
separators), no POSIX-only calls, and os.path.samefile has worked correctly on Windows
since Python 3.2.
Development
pip install -e .[test]
pytest
pytest tests/test_core.py::test_redact_pdf_literal_term # single test
AI-assisted development
This project's code, tests, and documentation were developed with the assistance of AI tools (Claude Code). Every change was reviewed before being published; please report any issues you find via the project's issue tracker.
License
MPL-2.0. The repository is REUSE compliant; to verify:
pipx run reuse lint.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pdfredactcli-0.1.0.tar.gz.
File metadata
- Download URL: pdfredactcli-0.1.0.tar.gz
- Upload date:
- Size: 27.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2f86a1cce49544e555fa7eae18d410a9ff74ef8d13e379f81d8087efd7de5d5
|
|
| MD5 |
d186f7ef8eda0a795aa5f8a00c2134b6
|
|
| BLAKE2b-256 |
3d71e67c76adc32cb1022a516567a33455133da641d2752237f68ebce4129edc
|
Provenance
The following attestation bundles were made for pdfredactcli-0.1.0.tar.gz:
Publisher:
pypi.yml on alberto743/pdfredact
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pdfredactcli-0.1.0.tar.gz -
Subject digest:
c2f86a1cce49544e555fa7eae18d410a9ff74ef8d13e379f81d8087efd7de5d5 - Sigstore transparency entry: 2465822013
- Sigstore integration time:
-
Permalink:
alberto743/pdfredact@aadca361b3d35ff52e052b50d6b2ce9078bc293f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/alberto743
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@aadca361b3d35ff52e052b50d6b2ce9078bc293f -
Trigger Event:
push
-
Statement type:
File details
Details for the file pdfredactcli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pdfredactcli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d055607ab309c07f1691e2026d4a57bdbc5c2654ecce747cc3cd58a023cb1dbb
|
|
| MD5 |
b4d566c5ecf0c469f40bbc9822db1fbd
|
|
| BLAKE2b-256 |
d92a6750767b6cbe26553dc4a74f9733d32708e9b3ea25440e21036fb3957b94
|
Provenance
The following attestation bundles were made for pdfredactcli-0.1.0-py3-none-any.whl:
Publisher:
pypi.yml on alberto743/pdfredact
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pdfredactcli-0.1.0-py3-none-any.whl -
Subject digest:
d055607ab309c07f1691e2026d4a57bdbc5c2654ecce747cc3cd58a023cb1dbb - Sigstore transparency entry: 2465822097
- Sigstore integration time:
-
Permalink:
alberto743/pdfredact@aadca361b3d35ff52e052b50d6b2ce9078bc293f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/alberto743
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@aadca361b3d35ff52e052b50d6b2ce9078bc293f -
Trigger Event:
push
-
Statement type: