2

dynamic web twain but its not working

asked 2013-09-10 09:23:49 +0800

anujtarun gravatar image anujtarun flag of India
205 6

updated 2013-09-10 12:17:02 +0800

hswain gravatar image hswain flag of India
1763 3 10
http://corejavaexample.bl...

Hi,

I am using dynamic web twain to scan document, but JS for it some times working and some times not working dynamicWebTwain1.AcquireImage(); method some times working and some times not working and also method is also some times working and and some times not working dynamicWebTwain1.attachEvent('OnPostAllTransfers', dynamicWebTwain1_OnPostAllTransfers);

below is code i am using



<script type="text/javascript">

            <![CDATA[

            var dynamicWebTwain1;
            var WebTWAIN;
            var seed;

            function f_scan(){


            //  alert("I am in f_scan()-->111--->");
            var attachmentType = $("#attachmentType").val();
            var selectedDevice = $("#deviceSetup").val();
            var fileName = $("#FileName").val();

            var BWorColour =$('input:radio[name=bwOrColour]:checked').val();
            //var SimplexDuplexFlag = $('input:radio[name=simplexDuplexFlag]:checked').val();
            var SimplexDuplexFlag ;

            var Resolution = $("#resolution").val(); 
            var AttachmentExtension= $("#FileType").val();
            var FileName = $("#FileName").val();
            //var ScanType = $('input:radio[name=ScanType]:checked').val();

            if (attachmentType == '') {
                alert('Please select Attachment Type.');
                return;
            }
            if (selectedDevice == '') {
                alert('Please select a Scanner.');
                return;
            }

            if (fileName == '') {
                alert('Please Enter File Name.');
                return;
            }

        //alert("AttachmentExtension -- >"+AttachmentExtension);

            if (AttachmentExtension != "PDF" && BWorColour=='B') {
                alert('Please Select Only PDF File Type For BW Scan');
                return;
            }


            for (var i = 0; i < dynamicWebTwain1.SourceCount; i++) {
                if(dynamicWebTwain1.SourceNameItems(i) == selectedDevice) {
                    dynamicWebTwain1.SelectSourceByIndex(i);
                }
            }

            try{
                dynamicWebTwain1.IfShowUI = false;
                dynamicWebTwain1.OpenSource();
                dynamicWebTwain1.IfShowIndicator = true;
            }catch(e){
                alert("Scanner not found! Kindly connect atlest one scanner and try again.");
                return;
            }

            dynamicWebTwain1.IfShowUI = document.getElementById("ShowUI").checked;
            dynamicWebTwain1.IfFeederEnabled = document.getElementById("ADF").checked;          
            dynamicWebTwain1.IfDuplexEnabled = document.getElementById("Duplex").checked;

            alert("I am here 1111---> "+dynamicWebTwain1.IfShowUI);
            alert("I am here 222---> "+ dynamicWebTwain1.IfFeederEnabled);
            alert("I am here 333---> "+dynamicWebTwain1.IfDuplexEnabled);


            if(BWorColour != '' && BWorColour == 'G'){
                dynamicWebTwain1.PixelType = 1;
            }else if(BWorColour != '' && BWorColour == 'B'){
                dynamicWebTwain1.PixelType = 0;
            }else{
                dynamicWebTwain1.PixelType = 2;
            }
        //  alert("After 111");

            /*
            if(SimplexDuplexFlag != '' && SimplexDuplexFlag == 'D'){
                dynamicWebTwain1.IfDuplexEnabled = true;
            }else{
                dynamicWebTwain1.IfDuplexEnabled = false;
            }
            */

        //  alert("After 22222");

            if(Resolution != ''){
                dynamicWebTwain1.Resolution = Resolution;

            }

             if (FileName == "") {
                    $('#FileName').val("ScanFile." + AttachmentExtension);  
                 } 
             if ($('#FileName').val().indexOf('.') < 0) {
                 $('#FileName').val($('#FileName').val() + '.' + AttachmentExtension);  
             }

        //   alert("After 3333");


             dynamicWebTwain1.IfAutoFeed = true;
             dynamicWebTwain1.IfDisableSourceAfterAcquire = true;
             dynamicWebTwain1.XferCount = -1;

             //alert("After 4444 -->>"+ScanType);

        //   alert("After 4444 -->>");

                //if (ScanType!= 'Single Page') {
                    //dynamicWebTwain1.MaxImagesInBuffer = 200;
            //  }

             /* if (getCheckedValue(ScanType) != 'Single Page') {
                    dynamicWebTwain1.MaxImagesInBuffer = 200;
                }*/


             alert("After 55555");

            alert("Calling AcquireImage Method ");

             dynamicWebTwain1.AcquireImage();

            alert("after AcquireImage Method 22222");

            dynamicWebTwain1.attachEvent('OnPostAllTransfers', dynamicWebTwain1_OnPostAllTransfers);

            alert("after AcquireImage Method 3333");

            }


        function dynamicWebTwain1_OnPostAllTransfers(){

            alert("I am in method dynamicWebTwain1_OnPostAllTransfers-->");

                var strActionPage;
                var strHostIP;
                var strImageName;
                var FileName;
                var zeros; 
                var lid = $("#lid").val();
                var folderRSN = $("#folderRSN").val();
                var folderType = $("#folderType").val();
                var attachmentDesc = $("#attachmentDesc").val();
                var attachmentDetail = $("#attachmentDetail").val();
                var fileType = $("#FileType").val();
                var fileName =  $("#FileName").val();
                //var ScanType = $('input:radio[name=ScanType]:checked').val();
                var ScanType;
                var attachmentCode = $("#attachmentType").val();
                var CurrentPathName = unescape(location.pathname);  
                var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);   

                strActionPage = CurrentPath+document.getElementById("hdnActionPageUrl").value;
                strActionPage += "&AttachmentCode="+attachmentCode+"&AttachmentDesc="+attachmentDesc+"&AttachmentDetail="+attachmentDetail+"&FileType="+fileType+"&FileName="+fileName+"&Lid="+lid;

                //alert("strActionPage-->"+strActionPage);
                //strActionPage = document.getElementById("hdnActionPageUrl").value;

                dynamicWebTwain1.HTTPPort = document.location.port
        //      alert("ScanType--->"+ScanType);
        //      alert("fileType--->"+fileType);

                //if (getCheckedValue(ScanType) == 'Multiple Pages') {
                //alert("strActionPage 22222222-->"+strActionPage);

                if (ScanType == 'Multiple Pages') {
                    if (fileType == 'PDF') {
                        dynamicWebTwain1.HTTPUploadAllThroughPostAsPDF(document.location.hostname, strActionPage, fileName);
                    } else {
                        dynamicWebTwain1.HTTPUploadAllThroughPostAsMultiPageTIFF(document.location.hostname, strActionPage, fileName);
                    }
                } else {
                //  alert("I am in else condition-->");
                    for (i=0; i<dynamicWebTwain1.HowManyImagesInBuffer; i++) {

                        alert("I am in loop ");

                        if (fileName.indexOf('####') > 0) {
                            zeros = "0000";
                            zeros= zeros.substr(0, 4 - ((i+1) +"").length); 

                            fileName.replace('####', zeros + (i+1));
                        } else if (fileName.indexOf('###') > 0) {
                            zeros = "000";
                            zeros= zeros.substr(0, 3 - ((i+1)+"").length); 

                            fileName = fileName.replace('###', zeros + (i+1));
                        } else if (fileName.indexOf('##') > 0) {
                            zeros = "00";
                            zeros= zeros.substr(0, 2 - ((i+1)+"").length); 

                            fileName = fileName.replace('##', zeros + (i+1));
                        } else {
                            fileName = fileName.replace('#', (i+1) + "");
                        }
                        //alert("after if condition 3333333333333333 am in loop ");

                        //alert("after sending documents 222---> "+document.location.hostname+"<<<-------->>>"+i+"<<------->>"+strActionPage+"<-------->"+fileName);

                         dynamicWebTwain1.HTTPUploadThroughPost(document.location.hostname, i, strActionPage, fileName);
                     //    alert("after sending documents 333---> "+document.location.hostname+"<<<-------->>>"+i+"<<------->>"+strActionPage+"<-------->"+fileName);

                       //  alert("dynamicWebTwain1.ErrorString-->"+dynamicWebTwain1.ErrorString);

                         if (dynamicWebTwain1.ErrorCode != 0 &&  dynamicWebTwain1.ErrorString != "HTTP process error") {
                            alert( dynamicWebTwain1.ErrorString);
                            //return true;
                        } 

                        alert("ScanType-->"+ScanType);
                        //if (getCheckedValue(ScanType) == 'Single Page') break;
                        //if (ScanType == 'Single Page') 
                            break;
                    //  alert("In else Condition loop");
                    }
                }

                zAu.send(new zk.Event(zk.Widget.$('$btnScan'), 'onScan', null, {toServer:true}));
                return true;    
            }

                function getCheckedValue(radioObj) {

                    if(!radioObj)
                        return "";
                    var radioLength = radioObj.length;
                    if(radioLength == undefined)
                        if(radioObj.checked) 
                            return radioObj.value;
                        else
                            return "";
                    for(var i = 0; i < radioLength; i++) {
                        if(radioObj[i].checked) {
                            return radioObj[i].value;
                        }
                    }
                    return "";
                }

                function f_showLoading(){
                    if (document.getElementById("idDetailTableLoadingBar")){
                        document.getElementById("idDetailTableLoadingBar").style.visibility = "visible";
                    }   
                }

                function f_hideLoading(){

                    if (document.getElementById("idDetailTableLoadingBar")){
                        document.getElementById("idDetailTableLoadingBar").style.visibility = "hidden";
                    }   
                }


                function f_selectFileType(){
                    var attachmentType = $("#attachmentType").val();
                    var lid = $("#lid").val();
                    var agencyType = $("#agencyType").val();

                    if (attachmentType != '') {
                        var postURL = "Attachment_Configuration_AJAX.jsp?lid="+lid+"&AttachmentCode="+attachmentType+"&AgencyType="+agencyType+"&isScan=true";
                        $.post(postURL, {}, function displayResult(response){
                            var resultData = response.split("!~#~!");
                            var BWorColour = resultData[0];
                            //var SimplexDuplexFlag = resultData[1];

                            var SimplexDuplexFlag;
                            var Resolution = resultData[2];
                            var AttachmentExtension = resultData[3];

                            //Set the AttachmentExtension setup from ValidAttachment
                            if(AttachmentExtension != ''){

                                $("#FileType").find("x\\:option").each(function(){

                                    if($(this).val() == AttachmentExtension)
                                        $("#FileType").val(AttachmentExtension);
                                });
                            }

                            //Set the BWorColour setup from ValidAttachment
                            if(BWorColour != ''){
                                if(BWorColour == 'B'){
                                    $("input:radio[name=bwOrColour]:nth(0)").attr('checked', true);
                                }else if(BWorColour == 'G'){
                                    $("input:radio[name=bwOrColour]:nth(1)").attr('checked', true);
                                }else{
                                    $("input:radio[name=bwOrColour]:nth(2)").attr('checked', true);
                                }
                            }

                            //Set the SimplexDuplexFlag setup from ValidAttachment
                            /*
                            if(SimplexDuplexFlag != ''){
                                if(SimplexDuplexFlag == 'D'){
                                    $("input:radio[name=simplexDuplexFlag]:nth(1)").attr('checked', true);
                                }else{
                                    $("input:radio[name=simplexDuplexFlag]:nth(0)").attr('checked', true);
                                }
                            }
                            */


                            //Set the Resolution setup from ValidAttachment
                            if(Resolution != ''){
                                $("#resolution").val(Resolution);
                            }

                        });
                }

                }

                function f_ScanType(thisObj){

                    if (thisObj.value == 'Multiple Pages') {

                        $("#FileType")[0].outerHTML = '<select  name="FileType" id="FileType" onChange="f_changeFileExtension(this);"><option selected="true" value="PDF">PDF</option><option value="TIF">TIF</option></select>';

                    } else if ($("#FileType")[0].outerHTML.indexOf("JPG") < 1) {
                        $("#FileType")[0].outerHTML = '<select  name="FileType" id="FileType" onChange="f_changeFileExtension(this);"><option selected="true" value="JPG">JPG</option><option value="PNG">PNG</option><option value="PDF">PDF</option><option value="TIF">TIF</option><option value="BMP">BMP</option></select>';
                    }
                }

                function f_simplexDuplexFlag(thisObj){
                    if(thisObj.value == 'D') {
                        $("#FileType").val('PDF');
                    }else if(thisObj.value == 'S'){
                        $("#FileType").val('JPG');
                    }
                }

                function f_changeFileExtension(fileTypeObject){
                    var fileName = $("#FileName").val();
                    if(fileName != ''){
                        var fileExtension = $(fileTypeObject).val();
                        var fileNamePart = fileName.split(".");
                        $("#FileName").val(fileNamePart[0]+"."+fileExtension);
                    }
                }

                function ExplorerType() {
                    ua = (navigator.userAgent.toLowerCase());
                    if (ua.indexOf("msie") != -1) {
                        return "IE";
                    }
                    else {
                        return "notIE";
                    }
                }

                function Pageonload() {
                     /*
                     Initialize the webpage, do not call Dynamic Web TWAIN directly
                     */
                     WebTWAIN = document.getElementById('DynamicWebTwain1'); //Make sure it's the right id for the object
                     seed = setInterval(ControlDetect, 500);//Wait 500ms after opening the webpage, call “ControlDetect” function
            }

            function ControlDetect() {
                     if (WebTWAIN.ErrorCode == 0) {//Here we use “WebTWAIN.ErrorCode” to determine if the object is fully initialized
                     clearInterval(seed); //If DWT is fully initialized, clear the interval  
                     /*
                     Here you can write the code to control DWT object
                     */   
                     }
                     timeout = setTimeout(function () { }, 10);//If the initiation of DWT is not ready, retry after 10ms
            }



            zk.afterMount(function() {

                OSType = "windows";

                    //For non-IE browsers on PC, use the MSI

                var strObject = "";
                strObject += "   </object>";

                if (ExplorerType() == "IE" && navigator.userAgent.indexOf("Win64") != -1 && navigator.userAgent.indexOf("x64") != -1) {
                    //For 64-bit IE, use the x64 CAB
                    strObject = '<object id="mainDynamicWebTwainIE" width="150px" height="200px" codebase="http://localhost:8090/module-web/resource/activex/DynamicWebTWAINx64.cab#version=9,0" classid="clsid:E7DA7F8D-27AB-4EE9-8FC0-3FEC9ECFE758"> ' + strObject;

                    //Display the right Plug-in and hide others
                    var objDivx64 = document.getElementById("maindivIEx64");
                    objDivx64.style.display = "inline";
                    objDivx64.innerHTML = strObject;

                    var obj = document.getElementById("maindivIE");
                    obj.style.display = "none";
                    var temp = document.getElementById("dwtcontrol");
                    dynamicWebTwain1 = document.getElementById("mainDynamicWebTwainIE");

                }
                else if (ExplorerType() == "IE" && (navigator.userAgent.indexOf("Win64") == -1 || navigator.userAgent.indexOf("x64") == -1)) {

                    //For 32-bit IE, use the normal CAB
                    strObject = '<object id="mainDynamicWebTwainIE" width="0px" height="0px" codebase="http://localhost:8090/module-web/resource/activex/DynamicWebTWAIN.cab#version=9,0" classid="clsid:E7DA7F8D-27AB-4EE9-8FC0-3FEC9ECFE758"> ' + strObject;
                    //Display the right Plug-in and hide others        
                    var objDivx86 = document.getElementById("maindivIEx86");
                    objDivx86.innerHTML = strObject;
                    objDivx86.style.display = "inline";

                    var obj = document.getElementById("maindivIE");
                    obj.style.display = "none";
                    dynamicWebTwain1 = document.getElementById("mainDynamicWebTwainIE");
                }
                else {

                    var strObjectFF = "";
                    //strObjectFF = ' <embed style="display: inline" id="mainDynamicWebTWAINnotIE" width="1px" height="1px" type="Application/DynamicWebTwain-Plugin" pluginspage="/DynamicWebTWAINPlugIn.msi"></embed>';

                    strObjectFF = ' <embed id="mainDynamicWebTWAINnotIE" style="display: inline"  width="1px" height="1px" type="Application/DynamicWebTwain-Plugin" pluginspage="/DynamicWebTWAINPlugIn.msi"></embed>';

                    //Display the right Plug-in and hide others
                    var objDivFF = document.getElementById("mainControlInstalled");
                    objDivFF.style.display = "none";
                    objDivFF.innerHTML = strObjectFF;
                    //var obj = document.getElementById("maindivIE");
                    objDivFF.style.display = "inline";
                    var obj = document.getElementById("maindivPlugin");
                    obj.style.display = "none";
                    dynamicWebTwain1 = document.getElementById("mainDynamicWebTWAINnotIE");
                }

                //Detect Dynamic Web TWAIN when it is loaded (after 0.5 sec)
                //seed = setInterval(ControlDetect, 500);
            //dynamicWebTwain1.ProductKey = "dsdsdsdsds43478E30A266347DFD860B7256CCD1E148CDDDBB5A26FC9dsdsdsdsEAAB0453741B501E30000000"

            //dynamicWebTwain1.ProductKey = "fdfdfdfd657CE347B492E556E9D70C8FD3880A0917B00259587B330000000";
            dynamicWebTwain1.ProductKey = "q21121212121";

            //dynamicWebTwain1.ProductKey = document.getElementById("scanProductKey").value;

        //  alert("dynamicWebTwain1.ProductKey-->"+document.getElementById("scanProductKey").value);

            window.onload = Pageonload; // Make sure the code executes after the page is loaded

        f_hideLoading();


            alert("dynamicWebTwain1.SourceCount 111 -- >"+dynamicWebTwain1.SourceCount);


            for (var i = 0; i < dynamicWebTwain1.SourceCount; i++) {

                document.getElementById("deviceSetup").options.add(new
                Option(dynamicWebTwain1.SourceNameItems(i),
                dynamicWebTwain1.SourceNameItems(i))); 

            }



            var attLabel = $("#attachmentLabel").val();
            var attValue = $("#attachmentValue").val();
            var labelArray = attLabel.split('-');
            var valueArray = attValue.split('-');

            for (var i = 0; i < labelArray.length; i++) {
                document.getElementById("attachmentType").options.add(new
                Option(labelArray[i],
                        valueArray[i])); }

            } );


            ]]>


</script>
delete flag offensive retag edit

Comments

Hi, maybe you can ask in Dynamic Web TWAIN's forum?

samchuang ( 2013-10-07 08:57:59 +0800 )edit

thnx, we have posted Dynamic Web TWAIN's forum.

anujtarun ( 2013-10-24 12:47:31 +0800 )edit
Be the first one to answer this question!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-09-10 09:23:49 +0800

Seen: 19 times

Last updated: Sep 10 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More