What is TWTwainJS for web?

TWTwain for web is a Terminalworks scanning product which allows you that visitors of your web site can perform scanning operations from their locally installed scaner devices.

How it works?

It has two parts:

  1. TWTwainJS - written in plain Javascript
  2. TWTwainClient - .NET windows application

On your website, where you want to provide web scanning functionality, you will use TWTwainJS product to create an instance of TWTwainJS. TWTwainJS instance opens a socket connection with the TWTwainClient. If you are web developer, you are primarly interested in TWTwainJS. TWTwainJS.zip is available at https://www.terminalworks.com/twtwainjs/downloads

TWTwainClient is the doing communication with web visitor's local scanners. Requirements to make it work:

  • web visitor must have already installed TWTwainClient on its computer
  • TWTwainClient is a .NET windows application and it will work only on Windows OS (Windows Vista and newer)
  • web visitor's scan devices must have TWAIN driver

TWTwainClient installer is available at https://www.terminalworks.com/twtwainjs/downloads

How to start using it?

If you are web developer: Extract TWTwainJS.zip. Let presume that you have index.html and index.js and you plan to support modern browsers which supports ES2015. in index.html

<script type="module" src="index.js"></script>

in index.js

import TWTwainJS, { ScanSettings, TWDeviceName, TWEvent, TWJSConnectionStatus } from "./src/TWTwainJS.js";
import { CapEnum, CapName } from "./src/TWTwainJSCapabilities.js";

const twTwainJS = new TWTwainJS("yourTwainInstance", "demoCompany", "demoKey");
twTwainJS
  .connectToClient(50000, 65535) // it will scan ports from 50000 to 65535
  .then((result) => {
    if (result.status === TWJSConnectionStatus.CONNECTED) {
      let scanSettings = new ScanSettings(TWDeviceName.DEFAULT);
      scanSettings.showUI = true;
      scanSettings.closeUIAfterAcquire = true;
      scanSettings.scanFormatType = CapEnum.TWScanFormatType.JPEG;
      twTwainJS
        .scan(scanSettings)
        .then((result) => {
          console.log("scan finished with result:", result);
        })
        .catch((error) => {
          console.log("scan finished with error:", error);
        });
    }
  })
  .catch((error) => {
    console.log("connectToClient error:", error);
  });

window.addEventListener(TWEvent.PAGE_SCANNED, function (e) {
  console.log(e.detail.scanResult);
  console.log("Current page", e.detail.scanResult.images.length);
});

This simple example will try to open socket connection with the TWTwainClient. Once opened, it will scan on the local default device in the jpeg format. Scanner's settings dialog will be shown. On every page scanned, TWEvent.PAGE_SCANNED is triggered with the scanned image in its detail. For more advanced use (like settings TWAIN capabilites, saving in different formats like PDF or TIFF, downloading scanned results...) please visit https://www.terminalworks.com/twtwainjs/documentation/js-examples

If you are web visitor of the site where TWTwainJS is implemented:

  1. Install TWTwainClient on your Windows OS machine.
  2. Visit the web page where TWTwainJS is implemented.

Licensing

To avoid watermark on your scanned pages, you need valid license key which you will retrieve on the purchase of the product. You set a license key on the TWTwainJS side.

const twTwainJS = new TWTwainJS("yourTwainJSInstanceName", "company", "licenseKey");

License is based on the allowed domain names which are set by a license owner while purchasing. So, if your website is on the domain www.yourdomain.com and you set that as allowed domain, license will work only if is run on www.yourdomain.com website. You have free 1 year upgrade and support.

Where can I see a demo to test how it really works?

Fully functional demo with watermark is available at https://www.terminalworks.com/twtwainjs/demo Also, source code of that demo is available in the TWTwainJS.zip file.

Where can I see some examples about implementing TWTwainJS?

Examples are available at this URL: https://www.terminalworks.com/twtwainjs/documentation/js-examples

Where can I see in the details about TWTwainJS?

Detailed reference is available at https://www.terminalworks.com/twtwainjs/documentation/js-reference

Where can I use TWTwainJS?

It is written in plain JS so it can be used in static sites, PHP, Django, ASP.NET Core... It is web technology agnostic. In TWTwainJS.zip is provided ES6 Javascript version which will work in modern browsers, and ES5 version for older browsers (like IE11).

TWTwainJS uses window, CustomEvent and WebSocket object so:

  • it can't be used directly in the main process of the electron app, but it can be used in the renderer process
  • it can't be used in Node applications