Skip to main content

Invert PDF colors page-by-page with parallel processing — dark-mode PDFs from any source

Project description

inv-pdf

PyPI version Python 3.8+ License: MIT GitHub

Invert PDF colors (dark-mode) for a file or entire directory — with parallel processing across CPU cores.


The Problem

Reading white-background PDFs at night or on OLED screens is painful. inv-pdf inverts every page of a PDF to produce a dark-mode version, with near-black pixels clamped to pure black to avoid muddy greys.


Installation

pip install inv-pdf

Dependencies: pymupdf and Pillow are installed automatically.


Usage

CLI

# Invert all PDFs in current directory (creates file_inverted.pdf for each)
inv-pdf .

# Specify output directory
inv-pdf ./pdfs -o ./dark-pdfs

# Custom DPI, suffix, and parallelism
inv-pdf ./pdfs --dpi 150 --suffix _dark --jobs 4

# Full help
inv-pdf --help

Python API

from inv_pdf import invert_pdf

# Invert a single PDF
invert_pdf("document.pdf", "document_inverted.pdf", dpi=300)

Options

Flag Default Description
DIR . Directory of PDFs to process
-o / --output Same as input Output directory
-s / --suffix _inverted Suffix added to output filenames
-d / --dpi 300 Render resolution (higher = better quality, slower)
-j / --jobs CPU count Number of parallel worker processes
--ext .pdf File extension to match

How It Works

  1. Opens each PDF with PyMuPDF (pymupdf)
  2. Rasterises each page at the specified DPI
  3. Inverts pixel values: 255 − x for each RGB channel via Pillow
  4. Clamps near-black pixels (all channels < 100) to pure (0, 0, 0)
  5. Re-encodes each page as PNG and embeds it back into a new PDF
  6. Preserves the original TOC and metadata
  7. Saves with deflate=True, garbage=4, clean=True for compact output

Requirements

  • Python 3.8+
  • pymupdf >= 1.23.0
  • Pillow >= 9.0.0

License

MIT © Santt997

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inv_pdf-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

inv_pdf-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file inv_pdf-0.1.0.tar.gz.

File metadata

  • Download URL: inv_pdf-0.1.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for inv_pdf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d98481e02495d7616efcdba0e09ed9682c3e0b2650babd86196edefa50544ab2
MD5 1079212161e9310fd339c92829db3938
BLAKE2b-256 bf230b3139d8f0fa0b972c73ebcb2fcbd557b69a151ee98dcabf46f3832a46c4

See more details on using hashes here.

File details

Details for the file inv_pdf-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: inv_pdf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for inv_pdf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14c381f3c486ac31400087995cb5a00c7d0f9b4a5b8a840b86ffa880716e1a87
MD5 4eeba7fd994c7f52ca98c2eee9528845
BLAKE2b-256 f7154e272e9cb8ccb1429d14c31f4277fc099d104f55c12051165ecf0419a3b6

See more details on using hashes here.

Supported by

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