OCR Module

The Optical Character Recognition (OCR) Module enables document scanning and text extraction in your application. It supports both headed (UI-based) and headless implementations.

Getting Started

Initialize OCR Module
1// Create an OCR module instance
2const ocr = oneSdk.component('ocr');

Implementation Options

Perfect for applications that need a pre-built UI component.

1

Add HTML Container

index.html
1<div id="ocr"></div>
2

Mount OCR Component

1// Mount OCR to your container element
2ocr.mount('#ocr');
3

Configure Viewport (Required)

index.html
1<head>
2 <meta name="viewport"
3 content="width=device-width, initial-scale=1.0"
4 charset="UTF-8" />
5 <title>OneSDK OCR</title>
6</head>

OCR Events

Implementation Example

1const ocr = oneSdk.component('ocr');
2
3ocr.on('input_required', async (inputInfo, status, callback) => {
4 try {
5 // Check document type and side required
6 console.log(`Need ${inputInfo.side} side of ${inputInfo.documentType}`);
7
8 // Your custom image capture implementation
9 const imageFile = await captureDocumentImage({
10 type: inputInfo.documentType,
11 side: inputInfo.side
12 });
13
14 // Send captured image back to OCR module
15 callback(imageFile);
16 } catch (error) {
17 console.error('Document capture failed:', error);
18 // Handle error appropriately
19 }
20});
Best Practices
  • Validate image quality before submission to reduce OCR failures
  • Implement proper error handling for all status codes
  • Consider device capabilities when choosing implementation type
  • Test with various document types and lighting conditions

Remember to handle potential errors and provide appropriate feedback to users during the document capture process.

Built with