Recently, Dynamsoft brought a remote scanner solution to enterprise-class applications. With Dynamic Web TWAIN v16.1.1, web developers can rapidly build cross-browser web apps to control remote scanners that are connected to PCs, servers, or embedded devices. The solution can dramatically reduce the number of scanners deployed in enterprises and thereby save money.
Dynamic Web TWAIN: The Real Cross-platform Scanner SDK for Web
Dynamic Web TWAIN is a set of JavaScript APIs designed for hardware scanner programming. It supports all mainstream operating systems and web browsers. With the SDK, web developers can create web document scanning and management apps by writing a few lines of code. To experience how Dynamic Web TWAIN works, try out the online demo.
Quick Usage
Install the SDK via NPM:
npm install dwt @types/dwt
Create a simple index.htm file for scanning documents in web browsers:
How to Access Remote Scanner Based on IP Address
Dynamic Web TWAIN supports both local and remote document scans as long as you have Dynamsoft service installed on Windows, Linux, macOS, and Raspberry Pi.
To run Dynamsoft service on your machine, you can download the full Dynamic Web TWAIN SDK package which contains a free 30-day trial license. Alternatively, you can install the platform-dependent scanning service from the online demo page and apply for a valid license key from the online portal.
For security, by default, the Dynamsoft service does not allow remote access. If you want to use the remote connection, currently you have to configure the setting manually:
1. Edit DSConfiguration.ini. Add your server IP address to the configuration file.
Server=<MACHINE IP ADDRESS>
Where is the configuration file located?
Windows: C:\Windows\SysWOW64\Dynamsoft\DynamsoftServicex64_16\DSConfiguration.ini
Linux, macOS and Raspberry Pi OS: /opt/dynamsoft/DynamsoftService/DSConfiguration.ini
2. Restart Dynamsoft service to activate the remote connection.
How to Scan Documents from Hardware Scanners to Your Web Browser?
Create a project folder and copy the Resources folder from Dynamic Web TWAIN installation directory to your project directory.
Create an index.htm file.
Add two HTML <select> elements: one for scanner server selection and the other for scanner source selection. You can hard-code the IP addresses if you know which machines are connected to scanners.
<select size="1" id="remote" style="position: relative; width: 220px;"><option>192.168.8.84</option><option>192.168.8.85</option></select><select size="1" id="source" style="position: relative; width: 220px;"></select>
Add an HTML <div> element and initialize the Dynamic Web TWAIN object with a valid trial license key:
<div id="dwtcontrolContainer"></div><script type="text/javascript">Dynamsoft.WebTwainEnv.UseLocalService = false;Dynamsoft.WebTwainEnv.AutoLoad = true;// Get a free trial license key from https://www.dynamsoft.com/CustomerPortal/Portal/Triallicense.aspxDynamsoft.WebTwainEnv.ProductKey = 'LICENSE-KEY';var DWObject = null;var DWServiceObject = null;Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady);function Dynamsoft_OnReady() {DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');if(DWObject) {DWObject.MouseShape = true;createScanObject(ip.value);}}
Comparing to the code for local scanner access, in addition to the Dynamic Web TWAIN object, you need to create another object for accessing the remote scanner based on an IP address used for websocket connection.
Once the remote connection is established, you can acquire image data from the remote scanner and load it into the image container created on the web-client side. Here is the code for triggering the remote document scan event:
One thing you need to know that when using SANE backend to query scanner devices on Linux, it takes a little long time. So be patient for awaiting the source list return if you want to use a remote scanner that is connected to a Linux system.
Now you can try to scan documents from any scanner placed in your office via your desktop and mobile web browser.
Source Code
https://github.com/yushulx/web-twain-remote-scan
How Can You Implement the Solution from Scratch by Yourself?
Dynamic Web TWAIN has done everything for you, including scanner control and network communication. If you are a coding enthusiast and would like to implement the server-side logic by yourself, try Dynamic .NET TWAIN, which can help you quickly set up document scanning functionalities in C#. The article https://www.dynamsoft.com/codepool/scan-documents-with-html5-websocket.html can guide you through the steps.