doksli-ocr
OCR for Indonesian ID cards (KTP) and tax cards (NPWP) that runs entirely in the browser, so document photos never leave the user's device.
- Year
- 2026
- Built with
- JavaScript, ONNX Runtime Web, WebAssembly, OCR
- Links
Onboarding forms in Indonesia often start with a photo of a KTP or NPWP, and that photo usually gets uploaded to a server just to read a few fields. doksli-ocr does the whole job on the user’s device with onnxruntime-web (WebAssembly): finding the card, straightening it, and reading every field. The image stays in browser memory.
import { createOcr } from "doksli-ocr";
const ocr = await createOcr();
const result = await ocr.recognize(file); // File from <input type="file">
console.log(result.docType, result.fields, result.needsReview);
Features
- KTP: NIK, name, place and date of birth, sex, blood type, address, RT/RW, village, district, regency/city, province, religion, marital status, occupation, nationality, and expiry.
- NPWP, old and new designs, 15 or 16 digits: NPWP number, NIK, name, address, and tax office (KPP).
- Detects whether the photo is a KTP or an NPWP.
- A card-corner model straightens tilted photos, including perspective shots and cards rotated 90° or 180°.
- Validates the NIK’s structure and checks it against the date of birth and sex, plus date, RT/RW, and NPWP formats.
- Corrects fields against dictionaries: administrative regions, religions, marital statuses, Dukcapil occupations, and DJP tax offices.
- A “needs review” flag on every field, computed from per-character confidence, so the form can highlight the fields the model isn’t sure about.
- About 3 MB of models plus about 2.9 MB of WASM runtime (compressed), downloaded once and cached by the browser.
Accuracy
Measured on 68 real photos (46 KTP, 22 NPWP) of people who are not in the training data, counting a field as correct only on an exact match.
| Field | Correct | Field | Correct |
|---|---|---|---|
| KTP NIK | 98% | KTP province / city | 98% / 100% |
| KTP date of birth | 96% | KTP RT/RW | 93% |
| KTP name | 87% | KTP address | 52% |
| NPWP number | 96% | NPWP tax office | 94% |
| All fields | 90% |
Fields that aren’t flagged for review are correct about 97% of the time. The flag catches about three quarters of the wrong fields while marking about 22% of all fields. Long names and addresses are the hardest, though the error is usually a single character.
Performance
A card takes about 0.5–0.6 s on a laptop with one WASM thread, and about 0.35–0.4 s with four threads on a cross-origin isolated page.
Responsible use
Client-side OCR results can be tampered with, so KYC and other important decisions still need server-side checks against official sources. The library reads printed text only and doesn’t verify that a document is genuine.