Skip to main content

pdfredact

Leggi questo in italiano

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).

The package is published on PyPI as pdfredactcli (the installed command is pdfredact).

With pip

pip install pdfredactcli

or, from a local clone of the repository:

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 pdfredactcli

Or, from a local clone of the repository, replace the last line with 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, in a new terminal (so ensurepath takes effect):

pipx install pdfredactcli

Or, from a local clone of the repository, run pipx install . from the repository folder instead.

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

  • PAGE is 1-based (page 1 = first page)
  • x0,y0,x1,y1 in PDF points (72 pt = 1 inch), origin at the top-left (same coordinate system returned by page.search_for())
  • Corner order doesn't matter: the rectangle is normalized.
  • A box that falls entirely outside the page redacts nothing: it's reported on stderr and not counted as a redacted occurrence, so a typo'd coordinate can't look like a success.

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

pdfredactcli-0.1.1.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdfredactcli-0.1.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file pdfredactcli-0.1.1.tar.gz.

File metadata

  • Download URL: pdfredactcli-0.1.1.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pdfredactcli-0.1.1.tar.gz
Algorithm Hash digest
SHA256 17022196b76a8490c24ab5d17f938f02251e1cf54b598ae8f36fe09a4a393b7d
MD5 dbc1caafc85bacd77fb6c666c6704c54
BLAKE2b-256 080bbf64655bfbe9b0c718d2125441ef78846bf0be8f3b0060164aa8aaa08beb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdfredactcli-0.1.1.tar.gz:

Publisher: pypi.yml on alberto743/pdfredact

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pdfredactcli-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pdfredactcli-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pdfredactcli-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eef8e52a0c9a3389fa6bc4ae6050784c75b033276e8133ecc56f9dce91e7005e
MD5 977a9ea396449d7a1441972f71b3a095
BLAKE2b-256 bbd749c59a5ac47e5984b738ba5f6b903676afaf59ae77e95556bf3d631db76a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdfredactcli-0.1.1-py3-none-any.whl:

Publisher: pypi.yml on alberto743/pdfredact

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page