Metadata-Version: 2.4
Name: scanlayer
Version: 1.2.1
Summary: Image (scan/photo) to searchable PDF, or raw OCR export, via Tesseract.
Author: Hyacinthe-primus
Author-email: Hyacinthe-primus <hyacintheatho91@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/Hyacinthe-primus/scanlayer
Project-URL: Documentation, https://Hyacinthe-primus.github.io/scanlayer/
Project-URL: Repository, https://github.com/Hyacinthe-primus/scanlayer
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: pytesseract>=0.3.10
Requires-Dist: Pillow>=10.0.0
Requires-Dist: reportlab>=4.0.0
Requires-Dist: opencv-python-headless>=4.8.0
Requires-Dist: numpy>=1.24.0
Requires-Dist: pdf2image>=1.17.0
Provides-Extra: test
Requires-Dist: pytest>=7.0; extra == "test"
Requires-Dist: pytest-cov>=4.1; extra == "test"
Requires-Dist: pypdf>=4.0; extra == "test"
Provides-Extra: bench
Requires-Dist: psutil>=5.9; extra == "bench"
Requires-Dist: pypdf>=4.0; extra == "bench"
Provides-Extra: yaml
Requires-Dist: PyYAML>=6.0; extra == "yaml"
Dynamic: license-file

<div align="center">
<img src="https://raw.githubusercontent.com/Hyacinthe-primus/scanlayer/main/scanlayer.png" alt="scanlayer" width="110"/>
<h1>scanlayer</h1>
<p><em> Turn scanned image or photographed document into searchable PDF, or raw OCR text/JSON/TSV/hOCR.</em></p>
</div>

**Turn a scanned image or photographed document into a searchable PDF**, or
export the raw OCR result as plain text, JSON, TSV, or hOCR. Use it as a
command-line tool or as a Python library; both are the same engine underneath.

[![PyPI version](https://img.shields.io/badge/pypi-v1.2.1-blue?style=for-the-badge)](https://badge.fury.io/py/scanlayer)
[![codecov](https://img.shields.io/codecov/c/github/Hyacinthe-primus/scanlayer?style=for-the-badge)](https://codecov.io/gh/Hyacinthe-primus/scanlayer)
[![Python](https://img.shields.io/badge/python-3.9%2B-3776AB?style=for-the-badge)](#)
![Platforms](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey?style=for-the-badge)
[![](https://img.shields.io/badge/docs-documentation-green?style=for-the-badge)](https://Hyacinthe-primus.github.io/scanlayer/)
[![GitHub last commit](https://img.shields.io/github/last-commit/Hyacinthe-primus/scanlayer?style=for-the-badge)](https://github.com/Hyacinthe-primus/scanlayer)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](LICENSE.md)

---

## Documentation

[Full documentation](https://Hyacinthe-primus.github.io/scanlayer/) – installation, CLI & API reference, configuration, output formats, examples, and troubleshooting.

## What it does

A scanned invoice, a phone photo of a letter, a stack of photographed pages:
scanlayer runs it through [Tesseract OCR](https://github.com/tesseract-ocr/tesseract)
and gives you back either:

- a **searchable PDF**: the original page image, with an invisible, precisely
  positioned text layer over it, so you can select and search text exactly
  where it visually appears, or
- the **raw OCR result** as `txt`, `json`, `tsv`, or `hocr`: text, per-word
  confidence, and bounding boxes, no PDF built at all.

Along the way it automatically straightens rotated/skewed pages, corrects
uneven lighting, denoises and sharpens for OCR accuracy without touching what
you actually see in the output, reconstructs correct reading order on
genuine multi-column pages, and races several OCR configurations against
each other to pick the most confident result.

| | |
|---|---|
| **Two interfaces, one engine** | `scanlayer` CLI and `import scanlayer` call the exact same pipeline |
| **Five output formats** | Searchable `pdf`, or raw `txt` / `json` / `tsv` / `hocr` |
| **Real column detection** | Two-column articles/letters read in correct order, not interleaved |
| **Batch, merge, native PDF input** | Convert a folder with bounded batch workers, merge pages into one PDF, or `--dry-run` a batch before spending time on OCR |
| **Incremental PDF pages** | Normal batch PDFs are rasterized page-by-page, keeping memory bounded by active workers |
| **One configuration surface** | `configure()`, a JSON/YAML profile, or CLI flags, documented precedence |
| **Debug overlay** | `--debug-image` draws every word, color-coded by confidence |

See the [feature catalog](https://Hyacinthe-primus.github.io/scanlayer/features.html) for the complete list, and
[Roadmap & Limitations](https://Hyacinthe-primus.github.io/scanlayer/roadmap.html) for what's deliberately out of
scope or not built yet.

## Requirements

- Python 3.9+
- [Tesseract OCR](https://github.com/tesseract-ocr/tesseract) (a separate, system-level install, see below)
- [poppler](https://poppler.freedesktop.org/) *only if* you feed scanlayer a native `.pdf` file directly

```bash
# Debian / Ubuntu
sudo apt install tesseract-ocr poppler-utils

# macOS (Homebrew)
brew install tesseract poppler

# Windows: Tesseract -> https://github.com/tesseract-ocr/tesseract/wiki
#          poppler    -> download a release, add its bin/ to PATH
```

Full detail, including how scanlayer locates the Tesseract binary
automatically and how to bundle your own, is in
[Installation](https://Hyacinthe-primus.github.io/scanlayer/installation.html) and [Bundling Tesseract](https://Hyacinthe-primus.github.io/scanlayer/bundling-tesseract.html).

## Install

```bash
pip install scanlayer
```

This installs the `scanlayer` console command and makes `import scanlayer`
available anywhere on the machine.

Working on scanlayer itself, or want to run it straight from a checkout with
no install at all?

```bash
git clone https://github.com/Hyacinthe-primus/scanlayer.git
cd scanlayer                        # the repo root, which contains requirements.txt
pip install -r requirements.txt
python -m scanlayer invoice.jpg -o invoice.pdf   # works with no install at all
```

See [CONTRIBUTING.md](CONTRIBUTING.md) for the full contributor setup
(editable install and running the test suite).

## Quick start

**As a CLI:**

```bash
scanlayer invoice.jpg -o invoice.pdf --lang fra+eng --dpi 300
```

**As a library:**

```python
import scanlayer

result = scanlayer.convert("invoice.jpg", "invoice.pdf", lang="fra+eng", dpi=300)
print(f"{result.words_count} words, {result.mean_confidence:.1f}% confidence")
```

Every CLI flag and library keyword argument in this project are named to
match each other (`--lang` ↔ `lang=`, `--dpi` ↔ `dpi=`, and so on), see
[Examples](https://Hyacinthe-primus.github.io/scanlayer/examples.html) for every
feature shown both ways, side by side, and
[CLI Reference](https://Hyacinthe-primus.github.io/scanlayer/cli-reference.html) /
[Library API](https://Hyacinthe-primus.github.io/scanlayer/library-api.html) for
the complete details of each.

A few more common cases:

```bash
# Batch-convert a folder with bounded parallelism (default: 2 workers)
scanlayer *.jpg -o ./converted/ --batch-workers 2

# Original sequential batch behavior
scanlayer *.jpg -o ./converted/ --batch-workers 1

# Merge several photographed pages into one searchable PDF
scanlayer page1.jpg page2.jpg page3.jpg -o report.pdf --merge

# Export raw OCR text/JSON instead of a PDF
scanlayer invoice.jpg -o invoice.json --format json

# See what OCR actually detected, color-coded by confidence
scanlayer invoice.jpg --debug-image

# Validate a batch before spending time on OCR: files exist,
# Tesseract reachable, output paths writable
scanlayer *.jpg -o ./converted/ --dry-run
```

```python
import scanlayer

# Batch with bounded parallelism (default: 2 workers)
batch = scanlayer.convert_batch(["*.jpg"], "./converted/", batch_workers=2)
print(batch.succeeded, batch.failed)

# Merge
scanlayer.convert_merge(["page1.jpg", "page2.jpg", "page3.jpg"], "report.pdf")

# Raw export
scanlayer.convert("invoice.jpg", "invoice.json", output_format="json")
```

`--workers` remains the merge-page worker option; use `--batch-workers` (or
`batch_workers=`) for normal non-merge batch conversion. The default batch
worker count is 2 and can be changed with `scanlayer.configure(batch_workers=...)`.
Normal batch PDFs are enumerated first and rasterized incrementally, so peak
memory is bounded by the active workers rather than total page count. Merge
still builds its full page set before writing the combined PDF.

## Repository layout

```
.
├── .github/           # FUNDING.yml
├── scanlayer/         # library source
│   ├── __init__.py
│   ├── __main__.py    # enables `python -m scanlayer`
│   ├── main.py        # public API: convert()/convert_batch()/convert_merge()
│   ├── config.py
│   ├── cli/           # argparse CLI: parser.py, run.py, dry_run.py
│   ├── fonts/         # bundled DejaVu Sans for the PDF text layer
│   ├── preprocessing/
│   ├── ocr/
│   ├── layout/
│   ├── pdf/
│   └── utils/
├── benchmarks/        # opt-in corpus and reproducible performance harness
├── tests/             # pytest suite
├── pyproject.toml
├── requirements.txt
├── README.md
├── CONTRIBUTING.md
├── SECURITY.md
└── LICENSE.md
```

## Development benchmarks

The reproducible benchmark harness is under `benchmarks/` and is not part of
the default pytest run:

```bash
pip install -e ".[test,bench]"
python -m benchmarks.bench_batch --repeats 2 --batch-workers 2
python -m benchmarks.bench_pipeline --repeats 2 --warmup 1
```

See `benchmarks/README.md` for the synthetic corpus, stage benchmarks, and
caveats.

## Contributing

Bug reports, fixes, and feature discussions are welcome: see
[CONTRIBUTING.md](CONTRIBUTING.md) for how to set up a development
environment and what to include in a pull request. The `tests/` directory
covers validators and the `--dry-run` flag, with cross-platform coverage for
Tesseract discovery on Windows/macOS/Linux; the opt-in `benchmarks/` suite
covers stage timings and batch throughput. Tests run with `pytest`
automatically in CI on every push and pull request; see
[Roadmap & Limitations](https://Hyacinthe-primus.github.io/scanlayer/roadmap.html)
and the [Adding tests](CONTRIBUTING.md#adding-tests) section of the
contributing guide for where coverage is thinnest.

## Support the project

scanlayer is free and MIT-licensed, maintained in spare time. If it saves you
time, there is no fee – but a little support goes a long way:

- **Star the repository** – the simplest signal that the project is worth
  maintaining.
- **Report bugs or request features** by opening a
  [GitHub Issue](https://github.com/Hyacinthe-primus/scanlayer/issues).
- **Contribute** a fix, test, or example – see
  [CONTRIBUTING.md](CONTRIBUTING.md).

## License

This project is licensed under the [MIT License](LICENSE.md).
