Metadata-Version: 2.4
Name: unmark
Version: 0.1.0
Summary: Remove pen/pencil markings from PDFs, fully offline - no AI, no network. Strips digital annotations losslessly and colour-pen marks from scans. (Experimental OCR reflow included.)
Author: Vibhanshu Singh
License: MIT
Project-URL: Homepage, https://github.com/singhvibhanshu/unmark
Project-URL: Repository, https://github.com/singhvibhanshu/unmark
Keywords: pdf,ocr,scan,annotations,cleanup,offline,exam
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
Classifier: Topic :: Text Processing
Classifier: Environment :: Console
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PyMuPDF>=1.24
Requires-Dist: numpy>=1.24
Provides-Extra: ocr
Requires-Dist: rapidocr-onnxruntime>=1.3; extra == "ocr"
Provides-Extra: lines
Requires-Dist: opencv-python-headless>=4.6; extra == "lines"
Dynamic: license-file

# unmark

**Remove pen/pencil markings from a PDF - fully offline. No AI, no network.**
Your files never leave your machine.

```bash
pip install unmark
unmark erase "marked.pdf"            # -> "marked clean.pdf"
```

## `erase` - the main feature

Strips the markings and hands back a clean PDF. It picks the right path automatically:

- **Digital annotations** (marks added in GoodNotes / Preview / Adobe, etc.)
  → deleted **losslessly**; the original page is restored exactly, text stays text.
- **Marks baked into a scan** → colour ink (red/blue/green pen) is removed by
  channel-dominance detection that leaves the printed text untouched. Options:
  `--pencil` (light-grey graphite), `--lines` (experimental underline erase).

```bash
unmark erase "scan.pdf" out.pdf --pencil     # also remove light pencil
unmark erase "scan.pdf" --sat 10             # remove more colour (may leave less)
unmark erase "notes.pdf" --lossless          # PNG pages instead of JPEG
```

### What `erase` can and can't do (honest)
| mark | result |
|------|--------|
| digital annotation | ✅ removed perfectly (lossless) |
| red / blue / green pen | ✅ removed; text preserved |
| light-grey pencil | ⚙️ removed with `--pencil` |
| **dark pen / heavy pencil at the same tone as the print** | ❌ cannot be removed offline - it carries no colour or brightness difference from the real letters. Only AI or manual erasing gets those. |

## `reflow` - experimental

> ⚠️ **Experimental.** `reflow` OCRs the printed text (offline, via
> [RapidOCR](https://github.com/RapidAI/RapidOCR)) and re-typesets a fresh PDF.
> On clean, single-column papers it's decent. On **dense, two-column, or heavily
> marked papers it is unreliable** - it misreads circled option markers, over-splits
> questions, and leftover dark handwriting bleeds into the text. **Always proofread.**
> Offline OCR simply can't match a vision model on messy scans; that's a hard ceiling,
> not a bug.

```bash
pip install "unmark[ocr]"                     # adds the offline OCR engine
unmark reflow "scan.pdf" --columns 1          # single-column works best
unmark reflow "scan.pdf" --pages 1-4          # limit to some pages
```

## How it works
`erase`: PyMuPDF renders each page → numpy colour/pencil masking → repackaged as a
compact greyscale PDF (or the annotation layer is simply deleted).
`reflow`: colour-clean → split columns → RapidOCR → parse → re-typeset (Story API).

## License
MIT.
