{% extends "base.html" %} {% block title %}Help{% endblock %} {% block content %}

pyocr toolkit guide

pyocr shows you what text you actually get out of a PDF or image, using three different methods, and how far apart they are. Use it to decide whether OCR is good enough for a document set, to pick an LLM for extraction, or just to get clean text out of a difficult file.

Quick start

  1. Upload a file with the Upload button (top right) or by dropping it anywhere on a page. You can upload several at once, or a .zip; those go into a workspace.
  2. The file opens on its Overview page. Each page gets a badge; scan means it has no embedded text, so it needs OCR or an LLM.
  3. Start an extraction: choose Tesseract or an LLM, a page range (or leave it empty for every page), and click Start extraction. A progress bar follows the job.
  4. Open the Page inspector to see one page next to all of its texts, or Full text to read the whole document from one source.
  5. Use Compare to measure two sources against each other, then export the text you want.

Tour of the pages

Home
Upload area, setup status and recent documents.
Library
Every uploaded document as a card showing how many pages have native, OCR and LLM text, and how many still have no text at all. Filter by status (Needs text, Scanned, All pages have text), by workspace or by name.
Workspaces
Named groups of documents, usually one batch upload each. Open one to rename it, add files, or take documents out of it.
Document → Overview
Start background extractions, list every source (each engine/model/prompt you've run), export a source, and see all pages as thumbnails.
Document → Page inspector
The page image on the left; tabs for native text, Tesseract, LLM and a per-page diff on the right. Search hits are drawn on the image. Run OCR or an LLM on just this page.
Document → Full text
The whole document from one source, page by page, optionally next to the page images. Find-in-text, copy and download.
Document → Compare
Pick a reference (A) and a candidate (B). You get the whole-document error rates, a per-page CER chart (click a bar to open that page) and the selected page's text side by side, with words only in A and only in B highlighted. It opens on the worst page.
Search
Search every document in the library at once.
Jobs
All background extractions with their progress, errors and token usage.
Providers
Which LLMs are configured, which settings are missing, a form to set keys and endpoints in the browser, and a Test connection button.
Models
Search vision models and see whether each is good for transcription, its price and why; list the models your key can use.

Workspaces and batch uploads

A workspace keeps documents that belong together (a folder of invoices, a zip of scans) under one name.

The three text sources, from first principles

1. Native text: the text the file already contains

A PDF page is a list of drawing instructions, for example "use font F at 11 pt, draw glyph 37 at (72, 700)". When a PDF is exported from Word, LaTeX or a browser, each glyph also carries a mapping back to a Unicode character. PyMuPDF follows those instructions and rebuilds words and lines from where the glyphs sit. This is exact, because nothing is guessed, but it only exists for born-digital files. A scanner only records a picture of the page, so a scanned PDF has no glyphs and no native text. A few PDFs also have broken glyph mappings, so native text can be gibberish even though the page looks fine.

2. Tesseract OCR: turning pixels back into characters

For a picture, all we have is pixels. pyocr renders the page at OCR_DPI (300 by default; small text needs enough pixels per character) and gives it to Tesseract, an open-source OCR engine. Tesseract finds lines of text, segments them, and recognises characters with a neural network (LSTM). It also reports a box for every word, which is how search can highlight OCR hits on the page. It is fast, free and private, but it reads shapes rather than meaning. Tables, multi-column layouts, stamps, low-contrast or skewed scans and handwriting are its weak spots.

3. LLM transcription: a vision model reading the page

The page is rendered to an image (LLM_DPI, with the longest side capped at LLM_MAX_EDGE_PX) and sent to a multimodal LLM with instructions to act as a transcription engine, not an assistant. Because it reads whole words and sentences in context, it is usually far more accurate than Tesseract on hard pages, and it understands layout. It can also make mistakes OCR never makes: quietly fixing a typo, normalising a date, skipping a repeated header, or occasionally inventing a plausible word for a smudge. Use the diff view to catch these. It also costs money and sends the page image to the provider.

LLM prompts

Every provider + model + prompt combination is stored separately, so you can run several and compare them. Results are cached: repeating a request costs nothing unless you click re-run.

Comparing: CER and WER

To find out how wrong a text is, compare it with a text you trust more: the reference. The basic quantity is edit distance (Levenshtein distance): the smallest number of single-item insertions, deletions and substitutions needed to turn the candidate into the reference.

reference : the cat sat
candidate : the bat sat        → 1 substitution (c → b)

CER = character edits / reference characters = 1 / 11 = 9.1 %
WER = word edits / reference words           = 1 / 3  = 33 %

Before scoring, whitespace is collapsed, because engines break lines differently and that is not a reading error. Ligatures such as fi are normalised to fi, and words hyphenated across a line break are joined. Case and punctuation can optionally be ignored as well.

Disagreement is not the same as error. "OCR vs LLM" tells you how much two engines disagree, not which one is right. For real ground truth, use a born-digital PDF: its native text is exact, so comparing OCR and each LLM against it shows how every engine performs on your kind of documents.

Typical workflows

Is OCR good enough for this batch of scans?

  1. Upload a representative document.
  2. Extract with Tesseract and an LLM (verbatim) on all pages.
  3. Compare: reference = LLM, candidate = Tesseract OCR. Check the overall CER and the worst pages.
  4. Open the worst pages in the inspector and read the diff. Are the errors in places that matter, such as numbers and names?

Which LLM should our pipeline use?

  1. Take a born-digital PDF, which has exact native text.
  2. Run two or three models on the same pages.
  3. Compare native text (reference) against each model (candidate). Lower CER means a more faithful model. Also look at the cost on the Overview page: each job shows its spend at list price in US dollars and rupees (set USD_INR_RATE to today's rate).
  4. Compare model A against model B on your real scans to see where they disagree.

Just get clean text out of a hard PDF

  1. Extract with an LLM using the Markdown prompt.
  2. Open Full text, check it next to the page images, then download as Markdown or JSONL.

Export and GenAI pipelines

Every source can be downloaded for the whole document (Overview → Export, or the Download menu in Full text):

Pages that have not been extracted for that source are left empty. An export never starts a paid LLM call.

Search is case-insensitive, and a phrase matches even when it is split across lines. In the page inspector, hits from the native text are drawn in yellow and Tesseract hits in blue, using each word's coordinates. LLM output has no coordinates, so its hits appear as text snippets. OCR and LLM text is only searchable on pages where it has been extracted.

Setting up providers

Easiest: open Providers, expand Set up in the browser on a provider card, paste your key and click Save. It takes effect immediately, is stored only on this machine in DATA_DIR/credentials.json (readable only by you), overrides environment variables, and is never sent back to the browser. Tick forget saved value to fall back to the environment again.

Alternatively run pyocr init to create a .env file, fill in the keys you have, and restart pyocr serve. Either way, click Test connection to check.

ProviderMinimum settings
Claude (Anthropic API)ANTHROPIC_API_KEY
OpenAIOPENAI_API_KEY
Azure OpenAIAZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_DEPLOYMENT
Claude on Azure (Foundry)ANTHROPIC_FOUNDRY_API_KEY, ANTHROPIC_FOUNDRY_RESOURCE
Google GeminiGEMINI_API_KEY
Ollama / vLLM / LM Studio / OpenRouterOPENAI_COMPATIBLE_BASE_URL, OPENAI_COMPATIBLE_MODEL

You can type any model or deployment name in the model box. The suggestions are only hints. The model must accept images: for local models, use a vision model such as qwen2.5vl or llama3.2-vision.

The Models page is a searchable catalog of vision models rated for this job (Excellent, Good, Fair: clean print only, Not suitable), with prices and the reason for each rating, and links to the benchmarks used. List models asks a provider which models your key can use and rates each one. The same rating appears under every model box as you type; names that aren't in the catalog are marked custom and still work. Ratings are a starting point: measure on your own pages with Compare.

Command line

pyocr serve [--host 0.0.0.0] [--port 8000] [--open]   # start this web app
pyocr init                                            # write a .env template here
pyocr doctor                                          # check Tesseract, providers, data dir
pyocr providers                                       # list providers and their status
pyocr extract FILE --engine llm -p anthropic --pages 1-5 --format jsonl -o out.jsonl
pyocr extract FILE --engine ocr                       # Tesseract, all pages, text to stdout
pyocr extract FILE --engine native --format md        # embedded text layer only
pyocr compare FILE -p openai -m gpt-6.2-sol                 # per-page OCR/native error rate vs an LLM
pyocr import a.pdf b.pdf scans.zip folder/ -w "Q3"    # add many files as one workspace (zips unpacked)
pyocr import FILE... --no-workspace                   # add to the Library without grouping

Documents processed from the command line also appear in the Library, so you can inspect them in the browser afterwards.

HTTP API

Everything this UI does goes through a JSON API. Interactive documentation is at /docs. The most useful endpoints:

POST /api/documents                              upload (multipart "file")
POST /api/uploads                                several files (multipart "files"), zips unpacked; optional workspace_id
GET  /api/workspaces                             list; POST {"name"} creates, PATCH /api/workspaces/{id} renames
POST /api/workspaces/suggest-names               {"filenames":["invoices.zip"]} → name ideas
POST /api/documents/{id}/jobs                    {"kind":"llm","pages":"1-5","llm":{"provider":"anthropic"}}
GET  /api/jobs/{job_id}                          progress
GET  /api/documents/{id}/sources                 what has been extracted
GET  /api/documents/{id}/export?source=llm&fmt=jsonl
GET  /api/documents/{id}/compare?a=llm&b=ocr      per-page CER/WER
POST /api/documents/{id}/pages/{n}/llm           transcribe one page (0-based n)

Data and privacy

Troubleshooting and FAQ

“Tesseract OCR is not available”
Install Tesseract (see Providers) and restart. For languages other than English, install the matching pack (for example tesseract-ocr-deu) and set TESSERACT_LANGUAGE.
A provider says “not configured”
The required environment variable is not visible to the server. Put it in .env in the directory where you run pyocr serve, or export it, then restart.
“authentication failed” / “model not found”
Check the key and the model name. For Azure, the model box needs your deployment name, not the model family.
“output hit the max token limit”
The page has a lot of text. The transcription is truncated; try the verbatim prompt, which is shorter than Markdown, or a model with a larger output limit.
The LLM “fixed” words that are misspelled on the page
That is a known LLM habit. The verbatim prompt discourages it, and the diff view makes it visible. If exact characters matter (IDs, legal text), compare against native text or OCR.
OCR is slow
Tesseract at 300 DPI takes roughly 1–5 s per page. Results are cached, so each page is only OCR'd once. Lowering OCR_DPI to 200 is faster and slightly less accurate.
Native text has words in the wrong order or odd characters
The PDF's internal structure or font mapping is unusual. This is exactly the kind of problem this tool is for: compare against OCR or an LLM to see the difference.
Can I use it with a local model and no internet?
Yes. Run Ollama with a vision model and set OPENAI_COMPATIBLE_BASE_URL=http://localhost:11434/v1.

Keyboard shortcuts (page inspector)

← / → or k / jprevious / next page
/focus the search box
1–5switch tab (native, OCR, LLM, compare, side by side). Side by side widens the text panel and shows all three texts in columns that scroll together; it stays on until you pick another tab.
ttranscribe the page with the selected LLM
orun OCR on the page
{% endblock %}