如何使用Dynamic Web Twain保存扫描的文档

时间:2018-06-06 04:42:21

标签: angular dynamic-web-twain

我在使用角度4的网络应用上使用动态网络twain 我在扫描后保存文档时遇到问题我在Twain文档中找到了这个函数:

function DynamicWebTwain_OnPostTransfer() { //fires after each scan
     var strFileName;
     var Digital = new Date();
     var Month = Digital.getMonth() + 1;
     var Day = Digital.getDate();
     var Hour = Digital.getHours();
     var Minute = Digital.getMinutes();
     var Second = Digital.getSeconds();
     var CurrentTime = Month + "_" + Day + "_" + Hour + "_" + Minute + "_" + Second;
     strFileName = "D:/temp/"+CurrentTime + ".pdf";
     DWObject.SaveAsPDF(strFileName,DWObject.CurrentImageIndexInBuffer); //save each scanned image as a different PDF file 
     if (DWObject.ErrorCode != 0) {  
         alert (DWObject.ErrorString);
     }
 }

但问题是我不知道在哪里把它放在我的twain.js中它应该如何工作 这是我的twain.js

var app = angular.module('WebScanning', []);
app.controller('twainControl',function twainControl($scope) {
$scope.acquireImage = function() {
    var DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer'); // Get the Dynamic Web TWAIN object that is embeded in the div with id 'dwtcontrolContainer'.
    DWObject.IfDisableSourceAfterAcquire = true;    // Source will be closed automatically after acquisition.
    DWObject.SelectSource();                        // Select a Data Source (a device like scanner) from the Data Source Manager.
    DWObject.OpenSource();                          // Open the source. You can set resolution, pixel type, etc. after this method. Please refer to the sample 'Scan' -> 'Custom Scan' for more info.
    DWObject.AcquireImage();

};

});

任何想法?

2 个答案:

答案 0 :(得分:0)

根据Dynamic Web TWAIN online guide,您可以按如下方式注册活动:

            var DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
            DWObject.RegisterEvent("OnPostTransfer", DynamicWebTwain_OnPostTransfer);

            function DynamicWebTwain_OnPostTransfer() { //fires after each scan
                var strFileName;
                var Digital = new Date();
                var Month = Digital.getMonth() + 1;
                var Day = Digital.getDate();
                var Hour = Digital.getHours();
                var Minute = Digital.getMinutes();
                var Second = Digital.getSeconds();
                var CurrentTime = Month + "_" + Day + "_" + Hour + "_" + Minute + "_" + Second;
                strFileName = "D:/temp/" + CurrentTime + ".pdf";
                DWObject.SaveAsPDF(strFileName, DWObject.CurrentImageIndexInBuffer); //save each scanned image as a different PDF file 
                if (DWObject.ErrorCode != 0) {
                    alert(DWObject.ErrorString);
                }
            }

答案 1 :(得分:0)

首先,对于Angular 4或5,更推荐的代码示例是this one,其中包括所有常见功能,包括扫描/加载/保存/上传等。编写代码的方式更多喜欢古老的Angular JS风格。

那就是说。以下代码段应适用于您当前的代码

    $scope.acquireImage = function() {
        var DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer'); 
        DWObject.RegisterEvent('OnPostTransfer', ()=>{
            var strFileName;
            var Digital = new Date();
            var Month = Digital.getMonth() + 1;
            var Day = Digital.getDate();
            var Hour = Digital.getHours();
            var Minute = Digital.getMinutes();
            var Second = Digital.getSeconds();
            var CurrentTime = Month + "_" + Day + "_" + Hour + "_" + Minute + "_" + Second;
            strFileName = "D:/temp/"+CurrentTime + ".pdf";
            DWObject.IfShowFileDialog=false;
            DWObject.IfShowProgressBar = false;
            console.log(DWObject.CurrentImageIndexInBuffer);
            DWObject.SaveAsPDF(strFileName,DWObject.CurrentImageIndexInBuffer, function(){},function(){}); //save each scanned image as a different PDF file 
            if (DWObject.ErrorCode != 0) {  
                alert (DWObject.ErrorString);
            }
        });
        DWObject.IfDisableSourceAfterAcquire = true;    // Source will be closed automatically after acquisition.
        DWObject.SelectSource();                        // Select a Data Source (a device like scanner) from the Data Source Manager.
        DWObject.OpenSource();                          // Open the source. You can set resolution, pixel type, etc. after this method. Please refer to the sample 'Scan' -> 'Custom Scan' for more info.
        DWObject.AcquireImage();