A lightweight, zero-dependency React document scanner with real-time edge detection, stability filtering, and perspective correction (bilinear warping) for high-resolution A4 captures.
npm install @uziee/document-scannerbash
npm install @uziee/document-scanner
`
📖 Usage
Import the DocumentScanner component into your React application and provide the callback props to handle scanning events.
$3
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| onCapture | (images: string[]) => void | Yes | Callback fired when user finishes scanning. Receives an array of base64 image data URLs. |
| onClose | () => void | No | Callback fired when user taps the close button (X) to exit the scanner without capturing. |
$3
`jsx
import React, { useState } from 'react';
import DocumentScanner from '@uziee/document-scanner';
function App() {
const [showScanner, setShowScanner] = useState(false);
const [scannedImages, setScannedImages] = useState([]);
const handleCapture = (images) => {
console.log(Captured ${images.length} document(s));
setScannedImages(images);
setShowScanner(false);
};
const handleClose = () => {
// User closed the scanner without capturing
setShowScanner(false);
};
return (
{showScanner && (
onCapture={handleCapture}
onClose={handleClose}
/>
)}
{scannedImages.map((img, i) => (
Scanned ${i + 1}} />
))}
);
}
export default App;
`
The component renders a full-screen camera interface for document scanning. It detects documents in real-time, applies stability filtering, and captures high-resolution images with perspective correction.
$3
- Close Button (X): Located in the top-right corner. Calls onClose to exit without capturing.
- Status Indicator: Shows "POSITION DOCUMENT" or "READY TO SCAN" based on detection state.
- Shutter Button: Captures the current document when detection is stable.
- Thumbnail/Done: Shows captured images count; tap to finish and return all images via onCapture`.