Auto Scan
Auto Scan lets the scanner drive the workflow: instead of calling scan() for every
document, you enable auto-scan once and the scanner watches its paper sensor,
automatically capturing each page as it is inserted. Captured images stream to the
browser in real time.
This is ideal for high-throughput, hands-free workstations (mailrooms, check-in desks, batch document capture) where an operator feeds documents one after another.
Auto-scan depends on the scanner reporting whether paper is in its feeder.
On Windows, any scanner with a feeder whose TWAIN driver reports paper state can drive auto-scan.
On macOS, that paper state has to come from the scanner's ImageCaptureCore (ICA) driver,
and reporting it is a custom capability of Ambir's own ICA driver for Ambir sheetfed
scanners. ICA drivers from other manufacturers will most likely not report it, in which case
auto-scan waits for a page that it never sees. Treat auto-scan on macOS as supported on
Ambir sheetfed scanners only, and use scan() for everything else — on-demand scanning
works on any supported scanner.
See Auto-Scan Never Triggers if you need to confirm this for a particular scanner.
How it works
- Enable auto-scan with your desired scan settings.
- Listen to the auto-scan event stream. Each document scanned is delivered to your
onImagecallback as it is captured. - Disable auto-scan when you are done.
Under the hood the SDK opens a Server-Sent Events
connection to GET /api/twain/autoscan/events, so images arrive without polling.
Basic usage
const scanner = new ASWCNScannerBridge();
// 1. Open a scanner
const sources = await scanner.getSources();
await scanner.openSource(sources[0].name);
// 2. Enable auto-scan (accepts the same parameters as scan(); see the
// note on imageFormat below)
await scanner.enableAutoScan({
resolution: 300,
colorMode: 'Color',
autoCrop: true
});
// 3. Receive each document as it is scanned
const stream = await scanner.startAutoScan({
onImage: (image) => {
const img = document.createElement('img');
img.src = `data:${image.mimeType};base64,${image.base64Data}`;
document.getElementById('results').appendChild(img);
},
onDisabled: () => console.log('Auto-scan stopped'),
onError: (err) => console.warn('Auto-scan stream error', err)
});
The image object delivered to onImage has the same shape as a normal
scanned image, including ocrText and
barcodes when those features are enabled.
Stopping
Turn off auto-scan and close the stream when finished:
await scanner.disableAutoScan();
scanner.stopAutoScan(stream);
Calling disableAutoScan() also causes the server to emit a disabled event, which
triggers your onDisabled handler and closes the stream automatically. Calling
stopAutoScan(stream) on the client is still good practice to release the connection
immediately.
Notes
- Open a scanner first. Auto-scan operates on the currently open source. If no
source is open,
enableAutoScan()returns an error. - One stream at a time. Open a single auto-scan event stream per page. Closing and reopening is fine, but avoid multiple concurrent streams.
- Barcode and OCR work the same as in a normal scan — pass
barcodeReadingEnabled: trueorocrEnabled: truetoenableAutoScan()(both are premium features). - Connection drops. If the connection to the scanner service drops (on Windows, for
example, when the Desktop App closes), the stream emits an
errorevent and ends. Re-checkcheckServiceStatus()before re-enabling. - macOS: empty scans. On macOS, auto-scan also switches itself off after three scans in
a row that fail or return no pages. Your
onDisabledhandler is called; re-enable when ready. - Auto-scan switches itself off when nobody is collecting. It stays on only while a page holds the event stream open. If no page collects images for five minutes — the tab was closed, the page reloaded, or the computer slept — auto-scan disables itself and discards any pages that were scanned but never delivered. Re-enable it when your page loads rather than assuming it is still on.
- Disabling discards undelivered pages.
disableAutoScan()throws away pages that were scanned but not yet delivered, so they never appear in a later session. - Output format. Auto-scan takes the output format as
imageFormat('Png','Jpeg','Tiff'or'Bmp');outputFormatis not recognised here, so auto-scan returns PNG unlessimageFormatis set.
REST equivalent
If you are not using the JavaScript SDK, the same flow is available over the
REST API: POST /api/twain/autoscan/enable,
GET /api/twain/autoscan/events (SSE), and POST /api/twain/autoscan/disable.