Dev Center
Table of contents

Thanks for Downloading Dynamic Web TWAIN 30-Day Trial!

Your download will start shortly. If your download does not begin, click here to retry.

Input

This section introduces different ways to get data into the Dynamic Web TWAIN buffer.

Scanners

Scan From a Local Scanner

Supported on desktop.

A local scanner refers to a scanner that is plugged in the same desktop via USB or is available on the local network and is accessible on the local desktop. The latter is generally known as a network scanner. A network scanner is connected to the LAN itself (cable or WI-FI) and is assigned a static IP. The scanner driver from the device vendor then configures the IP to connect to the scanner.

As far as Dynamic Web TWAIN is concerned, a network scanner is just like a local scanner because its driver has taken care of the network connection behind the scene.

The following code shows one way to acquire the image via the local Dynamsoft Service.

//Get the list of available TWAIN scanners
let scannerList=await DWObject.GetDevicesAsync()

//Select the desired scanner from the list [selecting the first scanner in the list for this example]
await DWObject.SelectDeviceAsync(scannerList[0])

//Acquire image (with configuration)
await DWObject.AcquireImageAsync({Resolution:100,IfShowUI:false})

Scan From an eSCL Scanner

Many modern scanners and multi-functional printers (MFPs) support the eSCL protocol. The protocol is a vendor-neutral network protocol that allows driverless scanning via ethernet, wireless and USB-connected devices. eSCL-compatible scanners advertise themselves via mDNS so that we can find them easily. mDNS is a zero-configuration service. It is implemented by Apple Bonjour and the open-source Avahi software packages.

See this blog post for more information about eSCL.

  • To scan from an eSCL Scanner to PC, the Dynamsoft Service must be installed on the client PC
  • To scan from an eSCL Scanner to Android, you must install the Android Service on the client device from the Play Store.

The following code shows one way to acquire the image via the eSCL protocol.

//Get the list of available eSCL scanners
let esclDeviceList=await DWObject.GetDevicesAsync(Dynamsoft.DWT.EnumDWT_DeviceType.ESCLSCANNER)

//Select the desired scanner from the list
await DWObject.SelectDeviceAsync(esclDeviceList[0])

//Acquire image (with configuration)
await DWObject.AcquireImageAsync({Resolution:100,IfShowUI:false})

Capture from cameras

Use DirectShow Cameras

To include the Webcam add-on, simply add a reference to the corresponding webcam JS file which is included in the resources folder.

<script src="Resources/addon/dynamsoft.webtwain.addon.webcam.js"></script>

The following code snippet shows how to use a camera through DirectShow.

function PlayVideo(bShow) {
    if (DWObject) {
        DWObject.Addon.Webcam.StopVideo();
        DWObject.Addon.Webcam.SelectSource("CAMERA-NAME");
        DWObject.Addon.Webcam.PlayVideo(DWObject, 80, function() {});
    }
}

function CaptureImage() {
    if (DWObject) {
        DWObject.Addon.Webcam.SelectSource("CAMERA-NAME");
        var funCaptureImage = function() {
            setTimeout(function() {
                DWObject.Addon.Webcam.StopVideo();
            }, 50);
        };
        DWObject.Addon.Webcam.CaptureImage(funCaptureImage, funCaptureImage);
    }
}

Load files

Load in this context means to open files which are accessible on the file system. These files can reside on the local disk or shared on the network.

As a lightweight library, Dynamic Web TWAIN only supports the following file types: BMP, JPG, TIF, PNG, and PDF. However, not all files of these types can be loaded correctly. Learn more here. If you come across a file that is of one of the supported file types but fails to load, please contact Dynamsoft Support.

Supported on desktop and mobile platforms.

The Open File dialog is only displayed on desktop. On mobile browsers, users are presented with the option to take a picture, use an existing image on the device, or open an existing file stored on the device.

var onSuccess = function() {
    console.log("Loaded a file successfully!");
};
var onFailure = function(errorCode, errorString) {
    console.log(errorString);
};
DWObject.IfShowFileDialog = true;
// PDF Rasterizer Addon is used here to ensure PDF support
DWObject.Addon.PDF.SetResolution(200);
DWObject.Addon.PDF.SetConvertMode(Dynamsoft.DWT.EnumDWT_ConvertMode.CM_RENDERALL);
DWObject.LoadImageEx("", Dynamsoft.DWT.EnumDWT_ImageType.IT_ALL, onSuccess, onFailure);

Open an existing file using its absolute path

Supported on desktop only.

var onSuccess = function() {
    console.log("Loaded a file successfully!");
};
var onFailure = function(errorCode, errorString) {
    console.log(errorString);
};
DWObject.IfShowFileDialog = false;
// PDF Addon is used here to ensure PDF support
DWObject.Addon.PDF.SetResolution(200);
DWObject.Addon.PDF.SetConvertMode(Dynamsoft.DWT.EnumDWT_ConvertMode.CM_RENDERALL);
/* "YOUR-FILE-PATH" - example path
 * Windows: 
 *   Local: "D:\\Files\\sample.pdf"
 *   LAN: "\\\\192.168.1.45\\sme\\sample.tif"
 * macOS: "/Applications/Images/sample.pdf"
 * Linux: "/home/userA/Files/sample.pdf"
 */
DWObject.LoadImage("YOUR-FILE-PATH", onSuccess, onFailure);

Drag and drop files onto the viewer area of a WebTwain instance

Only supported on desktop platform.

Download

Download is another type of Load. The only difference between a Download with what’s written above is that the file to load needs to be transferred to the local device via the network first. Dynamic Web TWAIN takes care of the whole process and supports both HTTP and FTP.

HTTP or HTTPS

Supported on desktop and mobile platforms. For this option, a URL is used to fetch the file. The URL either specifies the path of the file itself or points to a server-side script that eventually returns a file. Check out the code snippets below demonstrating both scenarios.

The URL specifies a file
/* The sample file path is: 
 * "http://localhost:300/files/sample.tif"
 */
var onSuccess = function() {
    console.log("Downloaded a file successfully!");
};
var onFailure = function(errorCode, errorString) {
    console.log(errorString);
};
DWObject.HTTPPort = 300;
DWObject.HTTPDownload("localhost", "/files/sample.tif", onSuccess, onFailure);
The URL points to a server-side script

The method HTTPDownloadEx is used because the file type needs to be specified.

JavaScript

/* The sample file path is: 
 * "http://localhost:300/files/sample.tif"
 */
var onSuccess = function() {
    console.log("Downloaded a file successfully!");
};
var onFailure = function(errorCode, errorString) {
    console.log(errorString);
};
DWObject.HTTPPort = 300;
DWObject.HTTPDownloadEx("localhost", "/getFile.aspx", Dynamsoft.DWT.EnumDWT_ImageType.IT_TIF, onSuccess, onFailure);

Server-side script

The server-side script can be written in any language and in any logic as long as it returns a file.

<%@ Page Language="C#"%>
<%
try
{
    String fileName = "sample.tif";
    String filePath = Server.MapPath(".") + "\\files\\" + fileName;
    System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
    Response.ClearContent();
    Response.ClearHeaders();
    Response.Clear();
    Response.Buffer = true;
    String fileNameEncode;
    fileNameEncode = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);
    fileNameEncode = fileNameEncode.Replace("+", "%20");
    String appendedheader = "attachment;filename=" + fileNameEncode;
    Response.AppendHeader("Content-Disposition", appendedheader);
    Response.WriteFile(fileInfo.FullName);
    }
catch (Exception)
{	}
%>

FTP

Supported on desktop platform.

The following code shows how to download a file from FTP.

/* The sample file path is: 
 * "ftp://192.168.8.20/files/sample.pdf"
 */
var onSuccess = function() {
    console.log("Downloaded a file successfully!");
};
var onFailure = function(errorCode, errorString) {
    console.log(errorString);
};
DWObject.FTPPort = 21;
DWObject.FTPUserName = "FTPUser";
DWObject.FTPPassword = "SomePassword";
DWObject.FTPDownloadEx("192.168.8.20", "/files/sample.pdf", Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF, onSuccess, onFailure);

Load files in binary or base64 string format

Supported on desktop and mobile platforms.

Dynamic Web TWAIN is capable of reading files in binary or base64 string format.

var onSuccess = function() {
    console.log("Loaded a file successfully!");
};
var onFailure = function(errorCode, errorString) {
    console.log(errorString);
};
/**
 * The following function loads a binary/blob. 
 * The method ConvertToBlob() is used to create
 * the Blob as an example but the actual Blob can 
 * come from anywhere.
 */
function loadFileFromBinary() {
    if (DWObject) {
        DWObject.ConvertToBlob(
            [0],
            Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
            function(result) {
                DWObject.LoadImageFromBinary(
                    result, onSuccess, onFailure);
            }, onFailure);
    }
}
/**
 * The following function loads a base64 string. 
 * The method ConvertToBase64() is used to create
 * the string as an example but the string can 
 * come from anywhere.
 * NOTE: the prefix such as "data:image/png;base64,"
 * should NOT be included in the data to load.
 */
function loadFileFromBase64() {
    if (DWObject) {
        DWObject.ConvertToBase64(
            [0],
            Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
            function(result) {
                DWObject.LoadImageFromBase64Binary(
                    result.getData(0, result.getLength()),
                    Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
                    onSuccess, onFailure);
            }, onFailure);
    }
}

Load files from the system clipboard

Supported on desktop only.

DWObject.LoadDibFromClipboard()

What physical document scanners does the Dynamic Web TWAIN SDK support?
How to use TWACKER to check if your device is TWAIN Compliant?
How to test if your scanner supports ICA scanning on Mac OS?
How to test if your device is SANE compliant?
Can I set scanning settings without using the default scanner’s UI? What pre-scanning settings do you support?
Can I hide offline scanner devices from the select source list?
Can I hide webcam devices from the select source list?

Is this page helpful?

YesYes NoNo

In this article:

latest version

    • Latest Version (18.4)
    • Version 18.3
    • Version 18.1
    • Version 18.0
    • Version 17.3
    • Version 17.2.1
    • Version 17.1.1
    • Version 17.0
    • Version 16.2
    • Version 16.1.1
    Change +