ocr
Make a scan searchable
Read the words on a scanned page and put them in the file, without changing how it looks.
- Reads
- a scanned PDF or a photograph of a page — application/pdf, image/png, image/jpeg, image/webp
- Writes
- one file — PDFs
- Tool page
- /ocr-pdf
Example
Make a scan searchable without changing how it looks.
Given
- scan.pdf — a scan: pages that are pictures of words
From code
import { loadDocument, runOperation } from '@pagecraft/core';
const scan = await loadDocument({ bytes, name: 'scan.pdf' });
const [output] = await runOperation('ocr', [scan], {
languages: [
'eng',
],
dpi: 300,
});
From a shell
pagecraft ocr scan.pdf --languages eng --dpi 300
What comes back
One PDF of 1 page, containing “Quarterly report”.
This example is run by the test suite. If it stopped being true, the build would fail.
Options
languages--languages
string[], any of
Language
What the page is written in. Add more than one for a document that mixes them.
Default: ['eng']
eng— Englishara— Arabicben— Bengalibul— Bulgariancat— Catalances— Czechchi_sim— Chinese (Simplified)chi_tra— Chinese (Traditional)dan— Danishdeu— Germanell— Greekest— Estonianfas— Persianfin— Finnishfra— Frenchheb— Hebrewhin— Hindihrv— Croatianhun— Hungarianind— Indonesianisl— Icelandicita— Italianjpn— Japanesekan— Kannadakor— Koreanlav— Latvianlit— Lithuanianmal— Malayalammar— Marathimsa— Malaynld— Dutchnor— Norwegianpol— Polishpor— Portugueseron— Romanianrus— Russianslk— Slovakslv— Slovenianspa— Spanishsqi— Albaniansrp— Serbianswa— Swahiliswe— Swedishtam— Tamiltel— Telugutha— Thaitur— Turkishukr— Ukrainianurd— Urduvie— Vietnamese
dpi--dpi
integer (dpi)
Density
How finely the page is drawn before it is read. 300 suits most scans.
Default: 300
deskew--deskew
boolean
Straighten a crooked page
A page fed through the scanner askew reads badly. This finds the angle and turns the picture back through it before reading, without changing the page itself.
Default: true
binarise--binarise
boolean
Sharpen to black and white
Faint and uneven scans read better as ink and paper. Only what is read is sharpened; the page keeps every shade it had.
Default: true
force--force
boolean
Read pages that already have text
A page whose words are already in the file is left alone, so that they are not written twice.
Default: false
pages--pages
string, a page selection: '1-3, 7, 9-', 'even', 'last'
Pages
Which pages to read: '1-3, 7, 9-'.
Default: 'all'
What it cannot do
- The reading is done by whatever engine the host has plugged in. How good it is, and which languages it can read at all, are that engine’s to answer.
- The page is not changed: the words go underneath the picture of them. A bad scan stays a bad scan, and the recognition is only as good as it.
- Confidence says how sure the engine is, which is not the same as whether it is right.
- A page carrying so much as a stamp counts as having text and is left alone. Read it anyway and it will carry both its own words and the recognised ones.
- On a crooked page the words are written along the crooked lines, so that selecting one lands on it. Every word is still found by a search, but a reader listing the text of such a page reads it in the order the words sit at rather than the order they were written in.