Skip to main content

SDK Reference

Complete API reference for the ASWCNScannerBridge JavaScript SDK.

Installation​

Copy aswcn-scanner-bridge.js into your web application:

<script src="path/to/aswcn-scanner-bridge.js"></script>

Constructor​

const scanner = new ASWCNScannerBridge(baseUrl);
ParameterTypeDefaultDescription
baseUrlstringnullService URL. If null, defaults to https://localhost:53052

Methods​

checkServiceStatus()​

Check if the AmbirScan Web Connect service is running and ready to scan. On Windows this means both the Windows Service and the Desktop App; on macOS, the single background service.

const isAvailable = await scanner.checkServiceStatus();
// Returns: boolean

getVersion()​

Get the version of AmbirScan Web Connect installed on the client machine. Useful for detecting whether a customer is running an older release.

const version = await scanner.getVersion();

Returns: Object

FieldTypeDescription
productNamestringProduct display name
serviceVersionstringVersion of the local scanning service (always available)
desktopVersionstringWindows: version of the Desktop app (only when connected). macOS: same as serviceVersion
desktopAppConnectedbooleanWindows: whether the Desktop App is currently connected. macOS: always true
legacybooleantrue when the client predates the version endpoint (a 404), indicating an older install that should be updated
const version = await scanner.getVersion();
if (version.legacy) {
console.warn('Older client installed - update recommended');
} else {
console.log(`Service ${version.serviceVersion}, Desktop ${version.desktopVersion}`);
}

getSources()​

Get a list of available scanners.

const sources = await scanner.getSources();

Returns: Array<Source>

FieldTypeDescription
namestringScanner name (use this for openSource())
manufacturerstringScanner manufacturer
modelstringScanner model
isOnlinebooleanWhether the scanner is currently connected
hasFeederbooleanWhether the scanner has a document feeder
hasFlatbedbooleanWhether the scanner has a flatbed
supportsDuplexbooleanWhether the scanner supports duplex scanning

openSource(sourceName)​

Open a scanner for scanning operations. Must be called before scan().

await scanner.openSource('TravelScan Pro');
ParameterTypeDescription
sourceNamestringExact scanner name from getSources()

closeSource()​

Close the currently open scanner. Call this when done scanning.

await scanner.closeSource();

getCapabilities(sourceName)​

Get the capabilities of a specific scanner. The scanner must be opened first.

const capabilities = await scanner.getCapabilities('TravelScan Pro');

Returns: Capabilities

FieldTypeDescription
resolutionsnumber[]Supported DPI values (e.g., [150, 200, 300, 600])
colorModesstring[]Supported color modes (e.g., ['Color', 'Grayscale', 'BlackAndWhite'])
supportsDuplexbooleanWhether duplex scanning is supported
supportsAutoRotatebooleanWhether auto-rotation is supported
supportsAutoDeskewbooleanWhether auto-deskew is supported
supportsAutoCropbooleanWhether auto-crop is supported
supportedPageSizesstring[]Supported page sizes (e.g., ['Letter', 'Legal', 'A4', 'Auto'])

getStatus()​

Get the current scanner status.

const status = await scanner.getStatus();

Returns: Status

FieldTypeDescription
isOnlinebooleanScanner is connected and powered on
isPaperLoadedbooleanPaper is in the document feeder
isSourceOpenbooleanA scanner source is currently open
ocrEnabledbooleanOCR is enabled

scan(params)​

Perform a scan with the specified parameters. A scanner must be opened first with openSource().

const images = await scanner.scan({
resolution: 200,
colorMode: 'Grayscale',
duplexMode: 'Simplex',
pageSize: 'Letter',
autoRotate: false,
autoDeskew: true,
autoCrop: true,
outputFormat: 'png',
barcodeReadingEnabled: false,
barcodeFilterLevel: 'Normal'
});

Scan Parameters​

ParameterTypeDefaultDescription
resolutionnumber200Scan resolution in DPI
colorModestring'Grayscale''Color', 'Grayscale', or 'BlackAndWhite'
duplexModestring'Simplex''Simplex', 'DuplexLongEdge', or 'DuplexShortEdge'
pageSizestring'Letter''Letter', 'Legal', 'A4', 'A5', 'A6', 'B5', 'Auto'
autoRotatebooleanfalseAuto-rotate pages to correct orientation
autoDeskewbooleantrueAuto-straighten skewed pages
autoCropbooleantrueAuto-crop to page edges
outputFormatstring'png''png', 'jpeg' (or 'jpg'), 'bmp', 'tiff' (or 'tif'). Case-insensitive.
jpegQualitynumber90JPEG quality, 1–100. Applies only when outputFormat is 'jpeg'.
barcodeReadingEnabledbooleanfalseEnable barcode detection (license required)
barcodeFilterLevelstring'Normal''Low', 'Normal', 'High', 'VeryHigh'
barcodeFormatsstring[][] (all)Only look for these symbologies, e.g. ['Pdf417']. See Choosing Symbologies
barcodeStopAfterFirstbooleanfalseStop reading a page as soon as one barcode is found
ocrEnabledbooleanfalseEnable OCR text extraction (license required)
requestTimeoutSecondsnumber0Timeout in seconds (0 = no timeout)
transferModestring(desktop setting, native)'Auto', 'Native', or 'Buffered'. Rarely needed. See Transfer Mode

colorMode, duplexMode, pageSize, transferMode and barcodeFilterLevel values are case-sensitive on at least one platform — use them exactly as written above. In scan(), an unrecognised value silently falls back to a default rather than failing the scan — for example, colorMode: 'grayscale' produces a color scan. enableAutoScan() and the REST /api/twain/scan endpoint reject an invalid value with HTTP 400 instead.

Output format in 4.1.0.0

Releases before 4.1.0.0 returned PNG for any lowercase outputFormat — 'jpeg', 'tiff' and 'bmp' included — and ignored jpegQuality. From 4.1.0.0 the requested format is returned; on Windows, JPEG is encoded at the requested jpegQuality. Use getVersion() if you need to know which behaviour a client has.

Transfer Mode​

transferMode selects how TWAIN moves image data from the scanner driver into the application. Native transfer is the default and is the right choice for almost every scanner — you should not normally need to set this parameter at all.

ValueBehaviour
'Auto'Use the configured default, which is native transfer
'Native'The driver returns a complete image in one transfer
'Buffered'The driver returns strips that TWAIN reassembles

Buffered transfer is offered only as an escape hatch. Several scanner drivers reassemble those strips incorrectly, which shows up as sheared pages, colour fringing, blank or black pages, or auto-crop being silently ignored. Set 'Buffered' only if a specific scanner is documented to require it, or if support asks you to.

Omit the parameter to use whatever is configured in the desktop app under Settings → Scanner Defaults → TWAIN Transfer Mode (Native out of the box). A value sent with the scan request overrides that setting for the one scan.

// Rarely needed - only for a scanner that specifically requires buffered transfer
const images = await scanner.scan({ transferMode: 'Buffered' });
note

transferMode was added in a later release. Installations older than that ignore the parameter instead of failing, so a scan that specifies it still succeeds — just with the scanner's previous transfer mode. Check the installed version with getVersion() if the setting appears to have no effect.

Scanned Image Response​

Returns: Array<ScannedImage>

FieldTypeDescription
base64DatastringBase64-encoded image data
mimeTypestringMIME type (e.g., image/png)
pageNumbernumberPage number (1-based)
widthnumberImage width in pixels
heightnumberImage height in pixels
resolutionnumberActual scan resolution in DPI
formatstringImage format name
fileSizeBytesnumberImage file size in bytes
ocrTextstringExtracted OCR text (if OCR enabled)
barcodesarrayDetected barcodes (if barcode reading enabled)

Barcode Result​

FieldTypeDescription
textstringDecoded barcode text
barcodeTypestringBarcode format (e.g., CODE_128, PDF_417, QR_CODE)
confidencenumberConfidence score (0.0 - 1.0)
isAamvabooleantrue if barcode contains AAMVA driver's license data
parsedDatastringParsed AAMVA data (when isAamva is true)

checkPaperLoaded()​

Check if paper is loaded in the scanner feeder.

const hasPaper = await scanner.checkPaperLoaded();
// Returns: boolean

checkScannerOnline()​

Check if the scanner is online and connected.

const isOnline = await scanner.checkScannerOnline();
// Returns: boolean

enableAutoScan(params)​

Enable auto-scan mode. The scanner watches its paper sensor and automatically captures each document as it is inserted — no per-page scan() call is needed. Captured images are delivered through the auto-scan event stream (see startAutoScan()).

await scanner.enableAutoScan({
resolution: 300,
colorMode: 'Color',
autoCrop: true
});

Accepts the same scan parameters as scan(), with one exception: the output format is set with imageFormat ('Png', 'Jpeg', 'Tiff' or 'Bmp') rather than outputFormat. Auto-scan does not recognise outputFormat and returns PNG unless imageFormat is set. Returns: { success, message }.

Auto-scan stays on only while a page is collecting images through startAutoScan(). If nothing collects images for five minutes — the tab was closed, the page reloaded, or the computer slept — auto-scan switches itself off and discards any pages that were scanned but never delivered. Call enableAutoScan() again when the page comes back.


disableAutoScan()​

Disable auto-scan mode and stop watching the paper sensor. Pages that were scanned but not yet delivered to the event stream are discarded.

await scanner.disableAutoScan();
// Returns: { success, message }

startAutoScan(handlers)​

Open the auto-scan event stream and receive each document as it is scanned. Call enableAutoScan() first. Uses Server-Sent Events under the hood and returns the underlying EventSource so you can stop listening later.

const stream = await scanner.startAutoScan({
onImage: (image) => {
const img = document.createElement('img');
img.src = `data:${image.mimeType};base64,${image.base64Data}`;
document.body.appendChild(img);
},
onDisabled: () => console.log('Auto-scan turned off'),
onError: (err) => console.warn('Stream error', err)
});
HandlerTypeDescription
onImagefunctionCalled with each scanned image object (same shape as a scanned image)
onDisabledfunctionOptional. Called when auto-scan is turned off (server-side or via disableAutoScan()); the stream closes automatically
onErrorfunctionOptional. Called on a stream error; the payload may be null on a connection drop

Returns: Promise<EventSource>


stopAutoScan(source)​

Close an auto-scan event stream returned by startAutoScan().

scanner.stopAutoScan(stream);

sendCommand(method, params)​

Send a raw TWAIN Direct command. Used internally by other methods but available for advanced use cases.

const response = await scanner.sendCommand('getSources');
ParameterTypeDescription
methodstringTWAIN Direct method name
paramsobjectOptional parameters

Platform Differences​

The SDK, the REST API and the request and response formats are the same on Windows and macOS — one web application works against both. What differs is the scanning and recognition engine underneath each client. A few options control features of the Windows engine that have no equivalent on macOS. On macOS they are ignored, not rejected — the scan still succeeds.

Scan options​

OptionWindowsmacOS
pageSizeAppliedIgnored — the scanner's full scan area is captured
autoDeskew, autoCropTwo separate switches, when the scanner driver supports themOne combined feature: setting either turns on both, when the scanner driver supports it
autoRotateApplied when the scanner driver supports itApplied when the scanner driver supports it
jpegQualityAppliedIgnored — the scanner driver chooses the JPEG quality
transferModeAppliedIgnored — not applicable on macOS
barcodeFormats, barcodeStopAfterFirstAppliedIgnored — every symbology is searched
barcodeFilterLevelAppliedApplied, with different thresholds. VeryHigh also discards barcodes shorter than six characters.
requestTimeoutSeconds: 0No timeoutA 300-second timeout
Auto-scanWorks on any scanner with a feeder. Stays on until disabled, or until no page collects images for five minutesAmbir sheetfed scanners only — it needs feeder paper state, which only Ambir's ICA driver reports. Stays on under the same rules, and also switches itself off after three scans in a row that fail or return no pages

Results and other calls​

AreaWindowsmacOS
getSources()hasFeeder, hasFlatbed and supportsDuplex are placeholder values (true, true, false) until the scanner is openedThese three are false until the scanner is opened
Barcode barcodeTypeThe 13 names in Supported Barcode FormatsThe same names, except that UPC_A is never reported; additional symbology names may also appear
Barcode confidenceCalculated by the Windows clientCalculated differently, so values aren't comparable between platforms
Duplicate barcodesRemovedNot removed — the same barcode can appear twice
OCR (ocrText)EnglishThe OCR language cannot be chosen in this release
getVersion()serviceVersion and desktopVersion are reported separatelyThere is no desktop app: desktopVersion matches serviceVersion and desktopAppConnected is always true
Licensing and settingsDesktop app (system tray)The admin page at https://localhost:53052/admin — see the macOS Installer guide

Your web application cannot detect which platform it is talking to in this release. Because options that don't apply are ignored rather than rejected, the same scan request works on both.


Complete Example​

const scanner = new ASWCNScannerBridge();

async function scanDocument() {
// 1. Check service availability
if (!await scanner.checkServiceStatus()) {
alert('Scanner service is not running');
return;
}

// 2. Get and display available scanners
const sources = await scanner.getSources();
if (sources.length === 0) {
alert('No scanners found');
return;
}

// 3. Open the first available scanner
const scannerName = sources[0].name;
await scanner.openSource(scannerName);

// 4. Check capabilities
const caps = await scanner.getCapabilities(scannerName);
console.log('Resolutions:', caps.resolutions);
console.log('Duplex:', caps.supportsDuplex);

// 5. Scan with barcode detection
try {
const images = await scanner.scan({
resolution: 300,
colorMode: 'Color',
barcodeReadingEnabled: true
});

images.forEach(image => {
// Display the image
const img = document.createElement('img');
img.src = `data:${image.mimeType};base64,${image.base64Data}`;
document.body.appendChild(img);

// Show barcodes
image.barcodes?.forEach(bc => {
console.log(`${bc.barcodeType}: ${bc.text}`);
});
});
} finally {
// 6. Always close the scanner
await scanner.closeSource();
}
}

Error Handling​

All SDK methods throw errors on failure. Wrap calls in try/catch:

try {
const images = await scanner.scan({ resolution: 300 });
} catch (error) {
if (error.message.includes('503')) {
console.error('Desktop app is not connected');
} else if (error.message.includes('504')) {
console.error('Scan timed out');
} else {
console.error('Scan failed:', error.message);
}
}