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
- 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.
- 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.
- 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.
- 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.
- 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.
- Several files or a .zip. Select or drop more than one file, or any
.zip, and a dialog asks where they go: a new workspace, an existing one, or no workspace (just the Library). A single PDF or image skips the dialog and opens right away, as before. - Name suggestions. When the files share a name, that comes first:
invoices-2024.zipsuggestsinvoices-2024, andreport-q1.pdf+report-q2.pdfsuggestreport. The other ideas are shortadjective-scientistnames such asfestive-albattani; the shuffle button gives new ones. Type anything you like instead; names must be unique (ignoring case) and at most 80 characters. - Zips are unpacked on upload. Every PDF or image inside becomes its own document. Unsupported files,
zips inside the zip, encrypted entries and files that won't open are skipped, and the dialog lists each one with the reason.
__MACOSXfolders and hidden files are ignored. Limits: 500 files per zip, each file up toMAX_UPLOAD_MB, and the zip's unpacked total up to 5 ×MAX_UPLOAD_MB. - Renaming. On the workspace page, click the pencil or double-click the name. Name ideas based on the files are offered there too.
- Adding later. On a workspace page, Add files or dropping files puts them straight into that workspace.
- Removing vs deleting. × on a card takes the document out of the workspace but keeps it in the Library; the bin deletes it everywhere. Deleting a workspace asks whether to delete its documents as well.
- A document can belong to more than one workspace. Its badges in the Library show which ones.
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
- Verbatim (default): plain text, line by line, nothing corrected, tables as
cell | cell. Use this to judge OCR, because both outputs then have the same shape. - Markdown: keeps structure (headings, lists, GFM tables). Closest to what you would feed a RAG or LLM pipeline.
- Custom: write your own instructions, for example "extract only the line items as CSV" or "transcribe the handwritten notes only".
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 %
- CER (character error rate) is the usual OCR quality figure. As a rough guide, under 2 % is excellent (green), 2–10 % is usable with care (amber), and over 10 % will hurt downstream extraction (red).
- WER (word error rate) is harsher, because one wrong letter makes the whole word wrong. It is closer to what matters for search and for exact values such as invoice numbers or amounts.
- Both can be over 100 % when the candidate contains a lot of extra text.
- The whole-document CER on the Compare page is micro-averaged: total edits divided by total reference characters. Long pages count more than short ones, which matches how much text is actually affected.
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?
- Upload a representative document.
- Extract with Tesseract and an LLM (verbatim) on all pages.
- Compare: reference = LLM, candidate = Tesseract OCR. Check the overall CER and the worst pages.
- 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?
- Take a born-digital PDF, which has exact native text.
- Run two or three models on the same pages.
- 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_RATEto today's rate). - Compare model A against model B on your real scans to see where they disagree.
Just get clean text out of a hard PDF
- Extract with an LLM using the Markdown prompt.
- 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):
- TXT: pages separated by
===== Page N =====. - Markdown: a
## Page Nheading per page. - JSON:
{document, source, pages: [{page, text, extracted}]}. - JSONL: one JSON object per page (
document_id, filename, page, source, text), ready for chunking, embedding or loading into a vector store.
Pages that have not been extracted for that source are left empty. An export never starts a paid LLM call.
Search
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.
| Provider | Minimum settings |
|---|---|
| Claude (Anthropic API) | ANTHROPIC_API_KEY |
| OpenAI | OPENAI_API_KEY |
| Azure OpenAI | AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_DEPLOYMENT |
| Claude on Azure (Foundry) | ANTHROPIC_FOUNDRY_API_KEY, ANTHROPIC_FOUNDRY_RESOURCE |
| Google Gemini | GEMINI_API_KEY |
| Ollama / vLLM / LM Studio / OpenRouter | OPENAI_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
- Everything is stored under
DATA_DIR(default./data): the original file, OCR results and LLM results as plain JSON. Workspaces are small JSON files inworkspaces/that list document ids. - A page image goes to an LLM provider only when you start a transcription for that page, and only to the provider you chose. Native text and Tesseract never leave your machine.
- API keys are read on the server and are never sent to the browser.
- There is no login. Keep it on
127.0.0.1(the default) or put it behind your own authentication before sharing it on a network.
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 setTESSERACT_LANGUAGE. - A provider says “not configured”
- The required environment variable is not visible to the server. Put it in
.envin the directory where you runpyocr 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_DPIto 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 / j | previous / next page |
| / | focus the search box |
| 1–5 | switch 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. |
| t | transcribe the page with the selected LLM |
| o | run OCR on the page |