Dynamic Web TWAIN properties / methods / events Introduction

When properly executed, Dynamic Web TWAIN is automatically initialized immediately after loading the page. After initialization, you can control it like any ordinary JS object. You can refer to the online API documentation to check all the built-in properties, methods and events of Dynamic Web TWAIN.

Basically, there are three ways you can use Dynamic Web TWAIN:

Properties ( the Properties )

Attribute is used to get or set a run time value Dynamic Web TWAIN subject, e.g. Resolution , Duplex , IfShowUI like.

/* Property */
/* Scan pages in 200 DPI */
DWObject.Resolution = 200;

Method ( Methods )

A method for invoking the built-in functions Dynamic Web TWAIN object, such as AcquireImage , SaveAsJPEG , Rotate the like. The syntax is very simple:

// Method
  
///
<summary> /// Rotates the image of a specified index in buffer by a specified angle.
  /// </summary>
///
<param name="sImageIndex" type="short">
specifies the index of image in buffer. The index is 0-based.
</param>
///
<param name="fAngle" type="float">
specifies the angle.
///
<param name="bKeepSize" type="bool">
specifies whether to keep the original size
///
<returns type="bool"></returns>
DWObject.Rotate(0, 45, false); // rotate the 1st image in the buffer by 45 degrees

Events ( Events )

It triggers the event reaches certain trigger point. For example, we have used a mouse click OnMouseClick event, a transmission image for OnPostTransfer events, and so on. Compared with properties and methods, event uses a bit tricky. Here, we'll touch.

Handling Events

Add an event listener
to add an event listener, you can use the built-in method registerEvent . See the following sample code:

<script type="text/javascript">
Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady);
var DWObject; 
/* OnWebTwainReady event fires as soon as Dynamic Web TWAIN is initialized and ready to be used. 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 OnPostTransfer will be triggered after a transfer ends. */
   /* your code goes here*/
}
</script> 

In the above code, we add a JavaScript function Dynamsoft_OnPostTransfer () as the event OnPostTransfer event listener. Alternatively, you can write the following code:

<script type="text/javascript">
Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady);
var DWObject; 
function Dynamsoft_OnReady() {
   DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
   DWObject.RegisterEvent("OnPostTransfer", function() { 
    /* your code goes here*/
   });
}
</script> 

Event arguments

There are some events with parameters. To OnMouseClick incident as an example:

/* sImageIndex is the index of the image you clicked on*/
OnMouseClick(short sImageIndex) 

When you create a corresponding JavaScript function (AKA, event listener), it may contain parameters and retrieve values ​​at runtime.

function DynamicWebTwain_OnMouseClick(index) {
    CurrentImage.value = index + 1;
}

or

DWObject.RegisterEvent("OnPostTransfer", function(index) { 
    CurrentImage.value = index + 1;
});

Special Events - 'OnWebTwainReady'
in all built-in event, there is a special event called 'OnWebTwainReady' of. Under normal circumstances, as long as Dynamic Web TWAIN object is initialized and ready for use, it will trigger this event. As you can see in the previous article, the recommended use is:

<script type="text/javascript">
Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady);
var DWObject; 
function Dynamsoft_OnReady() {
   DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
}
</script>

or

<script type="text/javascript">
   Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', function() {
     DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
   });
</script>

 

Released two original articles · won praise 4 · Views 4061

Guess you like

Origin blog.csdn.net/weixin_42320186/article/details/81134656