Refolio
Contents

Refolio reference (for AI agents)

Refolio turns scans of bound books into clean PDFs. It never changes the shape of a glyph: every step either moves pixels geometrically (and records how) or multiplies them by a smooth brightness gain.

If it is not installed: pip install --pre refolio (--pre while it is a beta). Where the VS Code extension has been set up, the command works in VS Code’s terminal as it is.

Run commands with --json and read the JSON Lines on stdout: zero or more progress lines, then exactly one result or error line. The exit code is 0 on success, 1 on an error or a failed check (guard, upscale).

{"event": "progress", "done": 3, "total": 61}
{"event": "result", ...}
{"event": "error", "message": "..."}

Commands

Command What it does result fields
refolio make IN.pdf OUT.pdf [--ocr auto\|on\|off] [--sr auto\|on\|off] [--size auto\|a5\|b5\|a4\|...] [--binding left\|right] [--layout on\|off] [--quality 80] [--workers N] A scanned book, easier to read. Spreads (scans wider than tall; --split auto\|on\|off) are split into pages at the gutter; each page is straightened, trimmed to the paper (the scanner ground is cleared) and placed on one standard paper size for the whole book, with the text block at the same place on every page (--size auto: the smallest standard size the pages fit in at 1:1; a named size enlarges or reduces to fit). Output resolution at most 400 dpi (--dpi). Page curl near the spine is flattened where it is visible (--dewarp auto\|on\|off). --binding right: the right page of a spread comes first (vertical text). Then: binding shadow removed, paper white, grain smoothed, and an invisible text layer (search, copy) when the text recognition is installed (--ocr auto). Colour pages stay colour, 1-bit pages stay 1-bit. --layout off: every scan stays one page, same size and resolution, only the brightness changes. Super-resolution (--sr auto, the default: when the engine is installed; on, off): grey pages scanned below 300 dpi (--sr-below) are super-resolved on the GPU to 400 dpi (--sr-target), each only if the glyph guard passes. progress lines carry stage: sr, analyse, pages, then ocr. src, dst, pages, seconds, ocr, sr (null, or accepted, rejected, skipped, error, rejected_pages), layout (null with --layout off, or size, mm, dpi, scale, spreads, dewarped, split_check: scans whose split is out of line with their neighbours, worth a look)
refolio setup [--ocr [--gpu]] [--sr] --ocr: the text recognition (NDLOCR-Lite, in its own environment, with uv) and its models (about 151 MB); --gpu: onnxruntime-gpu (NVIDIA). --sr: the super-resolution engine (Real-ESRGAN, a 47 MB download, checked by SHA-256). ocr, sr (the engines’ paths)
refolio doctor [--gpu] What is installed. --gpu runs the super-resolution engine once on a tiny image (uses the GPU; takes a few seconds). version, python, platform, home, packages, ocr (engine, gpu_runtime), sr (engine; with --gpu also ok, gpus, error)
refolio docs [--lang en\|ja] This text. text
refolio spreads BOOK.pdf Where each spread would be split, and spreads whose split jumps against the rest of the book (outlier). rows
refolio pages PAGE.jpg... Defect measures of split pages: edge_cut, shadow_depth, shadow_width, curvature. rows
refolio guard ORIGINAL PROCESSED Glyph-by-glyph agreement of two images with the same geometry. Exit 1 if any glyph changed. glyphs, worst_iou, n_failed, failed
refolio upscale PAGE --out FILE [--scale 4] Super-resolution (Real-ESRGAN, on the GPU). The result is written only if guard passes; otherwise FILE.rejected.* is written for inspection and the exit code is 1. accepted, out, rejected, glyphs, n_failed

split, process, view and inbox also exist (one-step tools and a folder watcher); see refolio --help.

How to use it for a person