【问题标题】:How to save scanned documents with Dynamic Web Twain如何使用 Dynamic Web Twain 保存扫描的文档
【发布时间】:2018-06-06 04:42:21
【问题描述】:

我在使用 angular 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();

};

});

有什么想法吗?

【问题讨论】:

    标签: angular dynamic-web-twain


    【解决方案1】:

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

    就是这么说的。以下 sn-p 应该适用于您当前的代码

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-09
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      • 2021-08-27
      • 1970-01-01
      • 2012-02-07
      • 1970-01-01
      相关资源
      最近更新 更多