Metadata-Version: 2.5
Name: refolio
Version: 0.1.1b1
Summary: Turn scans of bound books (flatbed or overhead) into clean, searchable PDFs, without changing a glyph.
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: numpy
Requires-Dist: opencv-python-headless<5,>=4.8
Requires-Dist: pypdfium2>=4.30
Provides-Extra: test
Requires-Dist: pytest; extra == 'test'
Description-Content-Type: text/markdown

# Refolio

**Turn scans of bound books into clean, searchable PDFs — without changing a glyph.**

[日本語](README.ja.md) · **Beta** · Guide: [yoshida-kd.github.io/refolio](https://yoshida-kd.github.io/refolio/)

Refolio takes a PDF of a scanned or photocopied book — open as spreads, or page by page — and makes one that is
easier to read: spreads split at the gutter, pages straightened and trimmed, page curl near the spine flattened,
one standard paper size for the whole book with the text block at the same place on every page, the binding
shadow and paper grain removed, and, optionally, an invisible text layer for search and copy.

It is a command-line tool (`refolio`) and a [VS Code extension](vscode-extension/README.md). Everything runs on
your machine.

## Principle

Refolio never draws a glyph. Every step either moves pixels geometrically (split, rotate, trim, flatten the curl,
place on the paper; each step is recorded, so coordinates can be carried between the scan and the result) or
multiplies them by a smooth brightness gain. Super-resolution is the only step that makes new pixels, and a
super-resolved page is used only if every glyph keeps its shape (`glyph_guard`).

## Install

```bash
pip install --pre refolio      # or: uv tool install --prerelease allow refolio (a beta)
refolio setup --sr             # super-resolution (Real-ESRGAN, 47 MB), used for scans below 300 dpi
refolio setup --ocr            # optional: the text layer (NDLOCR-Lite, about 0.5 GB)
refolio doctor                 # what is installed
```

Python 3.10 or later. PDFs are read with pypdfium2, so nothing else (poppler, Ghostscript) is needed.
`refolio setup --ocr` needs [uv](https://github.com/astral-sh/uv): the text recognition lives in its own
environment. Add `--gpu` to read on an NVIDIA GPU (onnxruntime-gpu with the CUDA and cuDNN libraries, about 2.4 GB).

## Use

```bash
refolio make book.pdf book.refolio.pdf                 # the whole book
refolio make book.pdf out.pdf --size b5                # another paper size (auto by default)
refolio make book.pdf out.pdf --binding right          # right-bound books (vertical text): right page first
refolio make book.pdf out.pdf --layout off             # keep every scan as one page; only the brightness changes
refolio make book.pdf out.pdf --ocr off --sr off       # without the text layer or super-resolution
```

Text recognition and super-resolution are used when they are installed (`--ocr auto`, `--sr auto`).
Super-resolution touches only grey pages scanned below 300 dpi.

Every command takes `--json` and then prints JSON Lines on stdout: `progress` lines, then one `result` or `error`.
`refolio docs` prints a reference written for AI agents (Claude Code and others), so an agent can run Refolio for
you.

## Beta

- Vertical text: give `--binding right`; it is not detected yet.
- Overhead scanners (ScanSnap SV600 and the like) are not tested yet.
- Text that was hidden in the fold when the book was scanned or copied cannot be recovered: press the book flat at
  the spine.

## Credits and licenses

MIT License.
Text recognition: [NDLOCR-Lite](https://github.com/ndl-lab/ndlocr-lite) (National Diet Library, Japan; CC BY 4.0).
Third-party software: [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
