Metadata-Version: 2.4
Name: pageledger
Version: 0.9.0
Summary: Text from scanned documents, with a record of how each page was read
Author: Peter Busscher
License-Expression: MIT
Project-URL: Homepage, https://github.com/peterbussch/pageledger
Project-URL: Documentation, https://github.com/peterbussch/pageledger/blob/main/docs/README.md
Project-URL: Changelog, https://github.com/peterbussch/pageledger/blob/main/CHANGELOG.md
Project-URL: Citation, https://github.com/peterbussch/pageledger/blob/main/CITATION.cff
Project-URL: Artifact Reference, https://github.com/peterbussch/pageledger/blob/main/docs/artifacts.md
Project-URL: PDF/OCR First Run, https://github.com/peterbussch/pageledger/blob/main/docs/pdf-ocr-first-run.md
Project-URL: OCR Options, https://github.com/peterbussch/pageledger/blob/main/docs/ocr-options.md
Project-URL: Issues, https://github.com/peterbussch/pageledger/issues
Project-URL: Source, https://github.com/peterbussch/pageledger
Keywords: document-ai,document-extraction,document-processing,data-provenance,ocr,ocr-pipeline,vlm,digital-humanities,multilingual-ocr,reproducible-research,research-software,historical-documents
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Text Processing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PyYAML>=6.0.2
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: jsonschema>=4.0; extra == "dev"
Requires-Dist: mypy>=1.15; extra == "dev"
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: ruff>=0.9; extra == "dev"
Requires-Dist: twine>=6.0; extra == "dev"
Requires-Dist: types-PyYAML>=6.0; extra == "dev"
Provides-Extra: pdf
Requires-Dist: pypdf[crypto]<7,>=6.21.4; extra == "pdf"
Provides-Extra: indra
Requires-Dist: indra-ocr<2,>=1.1.1; extra == "indra"
Provides-Extra: rapidocr
Requires-Dist: onnxruntime>=1.20; extra == "rapidocr"
Requires-Dist: rapidocr<4,>=3; extra == "rapidocr"
Provides-Extra: ru
Requires-Dist: pymorphy3==2.0.6; extra == "ru"
Requires-Dist: pymorphy3-dicts-ru==2.4.417150.4580142; extra == "ru"
Dynamic: license-file

# PageLedger: text from scanned documents, with a record of how each page was read

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/peterbussch/pageledger/main/assets/pageledger-lockup-horizontal-reversed.png">
    <img src="https://raw.githubusercontent.com/peterbussch/pageledger/main/assets/pageledger-lockup-horizontal.png" alt="PageLedger: the tallied page" width="440">
  </picture>
</p>

<p align="center">
  <a href="https://pypi.org/project/pageledger/"><img src="https://img.shields.io/pypi/v/pageledger" alt="PyPI"></a>
  <a href="https://github.com/peterbussch/pageledger/actions/workflows/ci.yml"><img src="https://github.com/peterbussch/pageledger/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
  <a href="https://pypi.org/project/pageledger/"><img src="https://img.shields.io/pypi/pyversions/pageledger" alt="Python versions"></a>
  <a href="https://github.com/peterbussch/pageledger/blob/main/LICENSE"><img src="https://img.shields.io/pypi/l/pageledger" alt="License"></a>
  <a href="https://doi.org/10.5281/zenodo.21340651"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.21340651.svg" alt="DOI"></a>
</p>

PageLedger turns a scanned or born-digital document into text, one page at a
time. For every page it keeps a record of how the text was read, and it lists
the pages a person should look at before the text is trusted. Everything it
writes is plain files in one folder: no service, no database.

It grew out of a Soviet census digitization project, and is written for
historians, archivists and anyone else who has to say where a transcription
came from.

## Read a document

```bash
pageledger process book.pdf --out jobs/book
```

`process` reads each page's own text first (a born-digital PDF carries it),
and sends the pages whose text is missing or looks wrong to an OCR engine on
your machine: Tesseract, in English, unless you choose otherwise. It never
calls a paid service unless you configure one. The folder `jobs/book` is
the *job*: the record of everything done to this one document.

On three pages of an 1877 book scanned by the Internet Archive, the first
blank and the others carrying the scan's earlier OCR, the screen shows:

```text
Reading book.pdf: each page's own text, then Tesseract OCR in English for pages that need it. Nothing is sent anywhere.
Finished: 3 pages read; 3 need a person.
The job is in jobs/book.
Why they need a person:
  2 pages: the selected text is Tesseract OCR (eng); the PDF's own text (an earlier OCR), the only other reading, has words run together, so their comparison does not count and nothing confirms the selected text.
  1 page: no reading found text, or one came back empty: the page may be blank.
Next: pageledger review jobs/book shows those pages beside their page images for checking.
Text out: pageledger export jobs/book --out book.md
```

When something looks wrong on a page (text missing, an engine unsure of many
words, two engines disagreeing), the job *holds* the page, and the screen says
how many pages need a person and why: which reading, and what is wrong with
it. Then:

- `pageledger inspect jobs/book` shows the job's report, `report.md`: where
  each page stands and which reading was selected, then the record of how
  every page was read.
- `pageledger review jobs/book` writes a review view into `jobs/book-review`
  to open in a browser: each page's image beside its text. Choose a decision for each
  page or correct its text there, and record the decisions with
  `pageledger review jobs/book --apply ~/Downloads/review.json --reviewer "Your Name"`,
  naming the `review.json` the view downloaded where your browser saved it.
- `pageledger export jobs/book --out book.md` writes the text out
  as plain text, Markdown, JSON lines or TEI, each page marked with whether a
  person has checked it.

The [first job](https://github.com/peterbussch/pageledger/blob/main/docs/document-first-run.md)
tutorial goes through these steps on a small example that needs no OCR engine.

## What a source can be

A PDF, a UTF-8 text file (pages separated by form feeds), one JPEG or PNG
page image, or a folder of them read as one document, pages in the order of
their file names. `pageledger fetch` downloads an item's page images from a
library's IIIF server into such a folder, with a record of where each image
came from. See [page images](https://github.com/peterbussch/pageledger/blob/main/docs/process-a-collection.md#page-images)
and [fetching from IIIF](https://github.com/peterbussch/pageledger/blob/main/docs/iiif.md).

## Choosing an OCR engine

Tesseract reads many languages: name them with `--lang` in Tesseract's codes,
such as `rus` or `deu+eng` (`pageledger doctor` lists the ones installed).
For two other engines that run on your machine, RapidOCR and Indra, write a
configuration with `pageledger init --engine rapidocr` (or `indra`) and pass it
to `process` with `--config`. A job can also use a second engine, a vision model, or the OCR
a library published with its scans (ALTO), to check the first reading. The
[OCR options](https://github.com/peterbussch/pageledger/blob/main/docs/ocr-options.md)
compare the engines,
[non-English and historical OCR](https://github.com/peterbussch/pageledger/blob/main/docs/multilingual-ocr.md)
covers language packs and pre-reform spelling, and the
[engine recipes](https://github.com/peterbussch/pageledger/blob/main/docs/engine-recipes.md)
give a working setup for each.

## Why a ledger

OCR makes mistakes that look like text, and a transcription that cannot be
traced is hard to cite or correct. PageLedger records, for every page, which
file it came from (by its SHA-256 hash), which engine read it with which
settings, what each engine produced, why the page was held, and who reviewed
or corrected it. `pageledger verify jobs/book` checks that the record is
intact, here or after the job folder has been deposited elsewhere, so a reader
of your edition can check any page against its source. It does not certify
that the text is right: that is what review is for.

## Runs: for building and testing pipelines

A job manages one document. The run commands (`run`, `rerun`, `compare`,
`classify`, `bundle`, `replay`) apply one extraction tool to the pages of
some files and record the same evidence; they are for building and testing a
pipeline over many files. This example needs no OCR engine:

```bash pageledger-tutorial
printf 'first page\fsecond page with a replacement character �\n' > sample.txt
pageledger init --run --out pageledger.yml
pageledger run sample.txt --config pageledger.yml --out runs/first
pageledger inspect runs/first
pageledger verify runs/first
```

The [first run](https://github.com/peterbussch/pageledger/blob/main/docs/first-run.md)
tutorial continues from here, and the
[CLI reference](https://github.com/peterbussch/pageledger/blob/main/docs/cli.md)
lists every command.

## Install

PageLedger needs Python 3.10 or later. For PDFs, install the `pdf` extra:

```bash
pip install "pageledger[pdf]"
pageledger doctor
```

OCR also needs Poppler and Tesseract, installed separately: on macOS
`brew install poppler tesseract`, on Debian or Ubuntu
`sudo apt-get install poppler-utils tesseract-ocr`. `pageledger doctor` says
which engines, tools and languages it finds. Jobs use POSIX file locks: use
macOS, Linux or, on Windows, WSL.

The [documentation](https://github.com/peterbussch/pageledger/blob/main/docs/README.md)
is arranged by task.

## Citing

Cite the software with
[CITATION.cff](https://github.com/peterbussch/pageledger/blob/main/CITATION.cff);
[share and cite results](https://github.com/peterbussch/pageledger/blob/main/docs/share-and-cite.md)
explains how to cite and deposit a job. Development setup is in
[CONTRIBUTING.md](https://github.com/peterbussch/pageledger/blob/main/CONTRIBUTING.md);
report a bug or ask a question in the
[issues](https://github.com/peterbussch/pageledger/issues), and to report how
PageLedger did on a collection, [open a corpus
report](https://github.com/peterbussch/pageledger/issues/new?template=corpus-report.yml).
A job, run or bundle someone sends you can name code to run: read
[folders you receive](https://github.com/peterbussch/pageledger/blob/main/docs/share-and-cite.md#jobs-runs-and-bundles-you-receive)
before resuming one, and report security problems privately as
[SECURITY.md](https://github.com/peterbussch/pageledger/blob/main/SECURITY.md) explains.

MIT license.
