Dynamic Web TWAIN: How to filter out specific source names

Scenario

You want to remove certain sources from the source list that is shown, for example removing any sources that have the word Cam in their name so that you can remove webcam sources.

Steps

  1. Create the list of sources as you normally would in Dynamic Web TWAIN
  2. Create a filter of the terms you want removed
  3. Remove items from the list based upon the filter

Sample Code

function Dynamsoft_OnReady() {
    Sources = document.getElementById("source");
    DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer'); // Get the Dynamic Web TWAIN object that is embeded in the div with id 'dwtcontrolContainer'
    if (DWObject) {
        var count = DWObject.SourceCount;
        for (var i = 0; i < count; i++){ var result = (DWObject.GetSourceNameItems(i).toUpperCase().indexOf('WEBCAM') >= 0) | (DWObject.GetSourceNameItems(i).toUpperCase().indexOf('CAMERA')>= 0);
	    if(result == 0){ // possibly a scanner device // add to drop down list } 
		Sources.options.add(new Option(DWObject.GetSourceNameItems(i), i));
	    }
        }
    }
}

function AcquireImage() {
    if (DWObject) {
        for(var i = 0; i < DWObject.SourceCount; i ++) {
	    if (DWObject.GetSourceNameItems(i) == Sources.options[Sources.selectedIndex].innerText){
	        DWObject.SelectSourceByIndex(i);
		break;
	    }
        }
        DWObject.OpenSource();
        DWObject.IfDisableSourceAfterAcquire = true;
	DWObject.AcquireImage();
    }
}
Is this page helpful?

Leave a Reply

Your email address will not be published.