New1 billion tokens free on sign-up — crawl, parse, chunk and embed on the houseSee pricing
SarvCrawlSarvCrawl

Glossary · Extraction and parsingUpdated

What is OCR (optical character recognition)?

Optical character recognition (OCR) converts images of text, such as scans, photos and screenshots, into machine-readable characters. It is the only way to get text out of a document that has no text layer.

01What OCR isof 05

What OCR is

A scanned contract or a phone photo of a receipt is a picture. It may look like a document, but to software it is pixels, and searching it for a word finds nothing. OCR reads the pixels and outputs text, so the document can be searched, chunked and embedded like any other.

The important thing to remember is that OCR output is a reconstruction, not an extraction. A PDF with a text layer hands you the characters its author typed. OCR hands you the characters a model believes it saw, and its accuracy varies page by page with scan quality, fonts, layout and language.

You need OCR for scanned PDFs, photographs, screenshots and image-only faxes, and sometimes for PDFs whose embedded text layer is missing or garbled. You do not need it for born-digital PDFs, which already contain their characters; running OCR on those only adds errors. See scanned vs text PDFs.

How OCR works

  1. Pre-processing. The image is deskewed, denoised and binarised so text stands out from background.
  2. Layout analysis. The engine finds text regions, columns, lines and reading order.
  3. Recognition. A model, today usually a neural network trained per script or language, converts each line image into characters.
  4. Post-processing. Language models and dictionaries correct likely errors, and the result is assembled into text.

Most engines need to be told the document's language, because recognition models are trained per language and script. Getting it wrong is one of the commonest causes of poor output.

# Upload a scan; OCR runs because the PDF has no text layer.
sarv-kb upload ./signed-contract.pdf --kb kb_abc123 --ocr-language eng --wait

Typical errors and pitfalls

  • Character substitution. rn read as m, 0 as O, 1 as l. Proper nouns and numbers suffer most, and they are the most valuable tokens for search.
  • Reading order. Multi-column pages, sidebars and form fields come out interleaved.
  • Tables. Cell boundaries are lost and values detach from their headers.
  • Silent truncation. A page that fails partway produces less text, not an error.
  • Scoring it wrongly. Comparing OCR output to the PDF's text layer returns zero, because a scan has no text layer. That measures whether the file was scanned, not OCR quality.

Scoring OCR output against a non-existent text layer does not measure OCR quality. It measures whether the document was scanned.

OCR has to be judged intrinsically: does it read like language, is the vocabulary plausible, are there runs of characters no word contains, is the line structure consistent. See scoring your own PDF conversion.

How SarvCrawl handles it

SarvCrawl accepts uploads of PDFs, Office files, EPUB, images and audio. Images, and scanned PDFs with no text layer, go through OCR, and the text lands in your knowledge base as markdown to be chunked and embedded like any page.

For PDFs, a conversion audit scores the result. It reports which mode it ran in, because scanned documents are scored on intrinsic properties of the output rather than against a text layer. Try it on a file at PDF to Markdown, or see real OCR results in the examples.

Frequently asked questions

How accurate is OCR?

It depends heavily on the input. Clean, high-resolution scans of printed text in a supported language come out well; low-resolution photos, handwriting, unusual fonts and complex layouts do not. Accuracy should be checked per document, not assumed.

Do I need OCR for every PDF?

No. PDFs created digitally usually have a text layer that can be extracted exactly. OCR is needed when the PDF is a scan or image with no text layer, or when the text layer is broken.

Can OCR read tables?

It can read the text in them, but preserving rows, columns and header relationships is much harder than reading the words. Check table output specifically.

SarvCrawl

Turn any site into a searchable knowledge base

Crawl pages and parse documents into clean markdown, then chunk, embed and search them from one API.