Files
fil/docs/snippets/wasm/ocr/ocr_extraction.md

35 lines
830 B
Markdown
Raw Normal View History

2026-06-01 23:40:55 +02:00
```typescript title="WASM (Browser)"
import { enableOcr, extractFromFile, initWasm } from "@kreuzberg/wasm";
await initWasm();
await enableOcr();
const fileInput = document.getElementById("file") as HTMLInputElement;
const file = fileInput.files?.[0];
if (file) {
const result = await extractFromFile(file, file.type, {
ocr: {
backend: "kreuzberg-tesseract",
language: "eng",
},
});
console.log(result.content);
}
```
```typescript title="WASM (Node.js / Deno / Bun)"
import { enableOcr, extractFile, initWasm } from "@kreuzberg/wasm";
await initWasm();
await enableOcr(); // Uses native kreuzberg-tesseract backend
const result = await extractFile("./scanned_document.png", "image/png", {
ocr: {
backend: "kreuzberg-tesseract",
language: "eng",
},
});
console.log(result.content);
```