Invert PDF colors page-by-page with parallel processing — dark-mode PDFs from any source
Project description
inv-pdf
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
- Opens each PDF with PyMuPDF (
pymupdf) - Rasterises each page at the specified DPI
- Inverts pixel values:
255 − xfor each RGB channel via Pillow - Clamps near-black pixels (all channels < 100) to pure
(0, 0, 0) - Re-encodes each page as PNG and embeds it back into a new PDF
- Preserves the original TOC and metadata
- Saves with
deflate=True, garbage=4, clean=Truefor compact output
Requirements
- Python 3.8+
pymupdf >= 1.23.0Pillow >= 9.0.0
License
MIT © Santt997
Project details
Release history Release notifications | RSS feed
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d98481e02495d7616efcdba0e09ed9682c3e0b2650babd86196edefa50544ab2
|
|
| MD5 |
1079212161e9310fd339c92829db3938
|
|
| BLAKE2b-256 |
bf230b3139d8f0fa0b972c73ebcb2fcbd557b69a151ee98dcabf46f3832a46c4
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14c381f3c486ac31400087995cb5a00c7d0f9b4a5b8a840b86ffa880716e1a87
|
|
| MD5 |
4eeba7fd994c7f52ca98c2eee9528845
|
|
| BLAKE2b-256 |
f7154e272e9cb8ccb1429d14c31f4277fc099d104f55c12051165ecf0419a3b6
|