image-to-text Β· vision β text (OCR) Β· WASM Β· ~185 MB
TrOCR is a transformer that does OCR the modern way: no hand-built pipeline, just a Vision
Transformer that looks at a cropped line of text and a text decoder that
writes it out, one token at a time β GRAND TOTAL: $42.99 β entirely on
your device.
| Model | Xenova/trocr-small-printed |
|---|---|
| Task / pipeline | image-to-text |
| Architecture | ViT-style image encoder β RoBERTa-style text decoder (VisionEncoderDecoder, cross-attention) |
| Input | A single line of printed text (crop to the line you want) |
| Output | The transcribed characters, generated token by token |
| Quantization | q8 (8-bit) ONNX β separate encoder + decoder graphs |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~185 MB, cached after first load |
| License | MIT (microsoft/trocr-small-printed) |
| Web APIs | WebAssembly, Web Workers, Canvas, FileReader β all Baseline widely available |
Pick or drop an image, then drag a box around one line of text and hit Read. TrOCR is a single-line reader, so the crop is the point β it transcribes what's inside the box.
Drag on the image to select a line.
OCR here is autoregressive generation, not template matching. The encoder reads the cropped line into patch embeddings once; then the decoder emits the transcription one token at a time, each conditioned on the image and everything decoded so far β which is why TrOCR can fix its own spelling from context. The trace below shows every token as it arrived, with the elapsed time. The first token is the slow one (it includes the image encode); the rest come faster.
Text trapped in an image is invisible to everything that isn't a person looking at it β you can't search it, copy it, translate it, or total it. OCR turns those pixels back into characters, and doing it locally makes it free, private, and offline-capable.
Crop a line β a sign or a receipt total β and read it, token by token.
Digitise a whole receipt: read every line into an editable, copyable list.
Live webcam OCR β point your camera at text and read it on the fly.
OCR β translation: read foreign text, then translate it locally.
The base call is two lines with Transformers.js:
import { pipeline } from "@huggingface/transformers";
const reader = await pipeline(
"image-to-text",
"Xenova/trocr-small-printed",
); // downloads + caches ~185 MB once
const out = await reader(lineCropURL, { max_new_tokens: 48 });
// β [{ generated_text: "GRAND TOTAL: $42.99" }]
The important bit is the input: TrOCR expects one line of text, so this page
crops the region you box before handing it over. For "See inside", it passes a
TextStreamer into the same call β the streamer fires once per decoded token, so the
page renders the transcription as it forms and records each token's arrival time, all off the
main thread in a Web Worker. Note: this SROIE-tuned checkpoint tends to normalise to
UPPERCASE β that's the model, not a bug.