Scanner Sidecar Solution with Raspberry Pi

Dynamic Web TWAIN for Raspberry Pi is on Dynamsoft Labs now. No matter whether you are a Dynamic Web TWAIN user or not, if you want to build a document scanning and management system with low cost, you should experience this edition. Build a smart and wireless scanner with a $35 Raspberry Pi, and scan documents from any HTML5 supported web browsers on any devices including PC, laptop, smartphone and tablet. In this article, I will illustrate how to set up the environment and build a simple web app for scanning documents with no plugin.

The Flowchart of Scanner Sidecar Solution

scanner sidecar solution with raspberry pi

Dynamic Web TWAIN consists of two parts: scanning service and JavaScript library. The scanning service, based on SANE, runs on Raspberry Pi.  It is capable of operating all scanners that connected to Raspberry Pi via USB. The JavaScript library loaded in web browsers communicates with the scanning service through websockets.

The Benefits

  • No connection needed between a scanner and a PC or server anymore. Replace the expensive devices with the cheap Raspberry Pi.
  • No plugin needed on client-side. Wirelessly scan documents in web browsers on PC, tablet, and smartphone via HTTP and WebSockets.
  • Quickly setup a remote scanning service with a scanner. It is a “plug and play” solution.

Wireless Document Scanning with Raspberry Pi

How to Install and Uninstall the Scanning Service

Download the package.

Install:

sudo dpkg -i dynamic_web_twain-arm-trial.deb

Uninstall:

sudo dpkg -r dynamsoft-webtwain-service

Sample Code

  1. Download Dynamic Web TWAIN SDK to get the full Resources folder.
  2. Create a new project with Resources folder and index.html.
  3. Set the IP address of Raspberry Pi:
var remoteIP = "192.168.8.51";
  1. Disable the property AutoLoad:
Dynamsoft.WebTwainEnv.AutoLoad = false;
  1. Set the product key. You can contact support@dynamsoft.com to get a trial license:
Dynamsoft.WebTwainEnv.ProductKey = "";
  1. Create a Dynamic Web TWAIN object:
var HTTP_PORT = 18618;
		var HTTPS_PORT = 18619;
		window.onload = function() {
			Dynamsoft.WebTwainEnv.CreateDWTObject('dwtObjectContainer', remoteIP, HTTP_PORT, HTTPS_PORT, function(obj) {
				DWObject = obj;
				DWObject.Width = 270;
				DWObject.Height = 350;
				console.log('DWTObject created.');
				if (DWObject) {
					var count = DWObject.SourceCount;
					if (count == 0 && Dynamsoft.Lib.env.bMac) {
						DWObject.CloseSourceManager();
						DWObject.ImageCaptureDriverType = 0;
						DWObject.OpenSourceManager();
						count = DWObject.SourceCount;
					}
					for (var i = 0; i < count; i++)
						document.getElementById("source").options.add(new Option(DWObject.GetSourceNameItems(i), i)); // Get Data Source names from Data Source Manager and put them in a drop-down box
				}
			}, function(es) {
				console.log(es);
			});
		};
  1. Acquire images:
function AcquireImage() {
			if (DWObject) {
				var OnAcquireImageSuccess, OnAcquireImageFailure;
				OnAcquireImageSuccess = OnAcquireImageFailure = function() {
					DWObject.CloseSource();
				};

				DWObject.SelectSourceByIndex(document.getElementById("source").selectedIndex); //Use method SelectSourceByIndex to avoid the 'Select Source' dialog
				DWObject.OpenSource();
				DWObject.IfDisableSourceAfterAcquire = true; // Scanner source will be disabled/closed automatically after the scan.
				DWObject.AcquireImage(OnAcquireImageSuccess, OnAcquireImageFailure);
			}
		}
  1. Connect scanners to Raspberry Pi. Open index.html to scan documents.

Video

Source Code

https://github.com/dynamsoftlabs/raspberrypi-document-scanning