0

我在使用 angular 4 的网络应用程序上使用动态网络吐温,扫描后保存文档时遇到问题我在吐温文档中找到了此功能:

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();

};

});

任何想法?

4

1 回答 1

0

首先,对于 Angular 4 或 5,更推荐的代码示例是包含所有常见功能的代码示例,包括扫描/加载/保存/上传等。您编写代码的方式更像是旧的 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();
于 2018-06-11T02:08:31.847 回答