OnGetFilePath 事件未触发

OnGetFilePath event not firing

用户扫描文档后 - 我想让他们 select 一个位置来保存文件,保存文件,最后 return 他们拥有的文件的路径刚刚保存。

我正在尝试使用“OnGetFilePath”事件,但它不起作用。

JS代码在这里:

var DWObject;

Dynamsoft.WebTwainEnv.AutoLoad = false;
Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady);


function LoadEnv() {
    Dynamsoft.WebTwainEnv.Load();
}

function Dynamsoft_OnReady() {
    DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');

    if (DWObject) {

        DWObject.IfShowFileDialog = true;
        DWObject.RegisterEvent('OnGetFilePath', OnGetFilePath); 

        DWObject.SelectSource(function () {
            DWObject.OpenSource();
            DWObject.IfDisableSourceAfterAcquire = true;
            DWObject.AcquireImage(OnAcquireImageSuccess, OnAcquireImageFailure);
        }, function () {
            console.log('SelectSource failed!');
        });
    }
}

function OnAcquireImageSuccess() {
    console.log('Successfully aquired image');
    SavePDF();
    DWObject.CloseSource();
}

//File saved to disk successfully 
function SavePDF() {
    DWObject.SaveAsPDF('file.pdf');
}

//Not Fired
function OnGetFilePath(bSave, filesCount, index, path, filename) {
    console.log("File Path!");
} 

这就是我所做的,我认为它会对你有所帮助。

  • 我下载了示例代码 - https://demo.dynamsoft.com/DWT/online_demo_scan.aspx
  • 我在 online_demo_scan.html

    上的“扫描”按钮旁边添加了一个按钮

  • 我在 online_demo_operation.js

    中向 Dynamsoft_OnGetFilePath 添加了提醒

    function Dynamsoft_OnGetFilePath(bSave, count, index, path, name) { 警报('OnGetFilePath event fired!'); }

当我点击按钮时事件确实触发。

根据文档

This event is triggered when 1. the ShowFileDialog method has finished; 2. the method LoadImageEx has finished with IfShowFileDialog set to true.

编辑:一些额外的代码来展示事件被触发后如何保存文件。

function Dynamsoft_OnGetFilePath(bSave, count, index, path, name) {
    var file_path = path + "\" + name + ".pdf";
    DWObject.IfShowFileDialog = false;
    DWObject.SaveAsPDF(file_path);
    alert(file_path);
}