Use Dynamic Web TWAIN

By default, Dynamic Web TWAIN automatically initializes after the page finishes loading. Once the Dynamic Web TWAIN object finishes initializing, you can start to call its methods, set its properties, etc. You can refer to our API Documentation to check all properties, methods and events of Dynamic Web TWAIN.

Properties

Properties are used to get or set a certain value of the Dynamic Web TWAIN object at runtime such as Resolution, Duplex, IfShowUI, etc.

DWObject.Resolution = 200; // Scan pages in 200 DPI
DWObject.IfDuplexEnabled = true; // Enable Duplex Scan
DWObject.IfFeederEnabled = true; // Use Document Feeder

Methods

Methods are used to call the built-in functions of the Dynamic Web TWAIN object such as AcquireImage(), SaveAsJPEG(), Rotate(), etc. The syntax is like this:

DWObject.Rotate(0, 45, false); // Rotate the 1st image in the buffer by 45 degrees
DWObject.Flip(); // Turn the image upside down

Events

Events are triggered when the program reaches certain trigger points. For example, OnMouseClick is triggered when you click the mouse, OnPostTransfer is triggered when one image is transferred, etc. Compared with Properties and Methods, Events are a bit tricky to use. We’ll talk about it a little more here. To check all the events, please refer to the API Documentation.

Handling Events

Add an event listener

To add an event listener, you can use the built-in method RegisterEvent(). Please refer to the sample code below:

Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady);
var DWObject;
/* OnWebTwainReady event fires as soon as Dynamic Web TWAIN is initialized. It is the best place to add event listeners */
function Dynamsoft_OnReady() {
    DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
    DWObject.RegisterEvent("OnPostTransfer", Dynamsoft_OnPostTransfer);
}
function Dynamsoft_OnPostTransfer() {
    /* This event handler will be called after a transfer ends. */
    /* Your code goes here*/
}

In the code above, we added the JavaScript function Dynamsoft_OnPostTransfer() as an event listener for the event OnPostTransfer. Alternatively, you can also write code as shown below:

Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady);
var DWObject;
function Dynamsoft_OnReady() {
    DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
    DWObject.RegisterEvent("OnPostTransfer", function () {
        /* Your code goes here*/
    };
}

Event with argument(s)

Some of the events have argument(s). Take the OnMouseClick event for an example:

OnMouseClick(Number nImageIndex) /* nImageIndex refers to the image you clicked on*/

When you create the corresponding JavaScript function (the event listener), you can include the argument(s) and retrieve the value(s) at runtime.

function DynamicWebTwain_OnMouseClick(index) {
    console.log(index);
}

or

DWObject.RegisterEvent("OnMouseClick", function (index) {
    console.log(index);
};

Special Event - OnWebTwainReady

Aside from the events mentioned in the API document, there is another one called OnWebTwainReady that is special. This event fires as soon as the Dynamic Web TWAIN object finishes initializing. As you may have seen earlier in the document, the recommended way to use it is:

Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady);
var DWObject;
function Dynamsoft_OnReady() {
    DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
}

or

var DWObject;
Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', function () {
    DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
};

results matching ""

    No results matching ""

    results matching ""

      No results matching ""