简体   繁体   English

OnGetFilePath事件未触发

[英]OnGetFilePath event not firing

After a user has scanned a document - I would like to allow them to select a location to save the file, save the file, and finally return the path to the file they have just saved. 用户扫描文档后-我想允许他们选择保存文件的位置,保存文件,最后将路径返回到他们刚刚保存的文件。

I am trying to use the " OnGetFilePath " event but it's not working. 我正在尝试使用“ OnGetFilePath ”事件,但是它不起作用。

JS Code is here: 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!");
} 

This is what I did and I think it will help you. 这就是我所做的,我认为它将为您提供帮助。

  • I downloaded the sample code - https://demo.dynamsoft.com/DWT/online_demo_scan.aspx 我下载了示例代码-https://demo.dynamsoft.com/DWT/online_demo_scan.aspx
  • I added a button next to the Scan button on online_demo_scan.html 我在online_demo_scan.html的“扫描”按钮旁边添加了一个按钮

    <input id="btnTest" value="TEST" type="button" onclick="DWObject.ShowFileDialog(false, 'JPG,PNG,TIF', 0, '', '', true, true, 0);"/> <input id =“ btnTest” value =“ TEST” type =“ button” onclick =“ DWObject.ShowFileDialog(false,'JPG,PNG,TIF',0,'','',true,true,0);” />

  • I added an alert to Dynamsoft_OnGetFilePath in online_demo_operation.js 我在online_demo_operation.js中向Dynamsoft_OnGetFilePath添加了警报

    function Dynamsoft_OnGetFilePath(bSave, count, index, path, name) { alert('OnGetFilePath event fired!'); 函数Dynamsoft_OnGetFilePath(bSave,计数,索引,路径,名称){alert('OnGetFilePath事件被触发!'); } }

And the event does fire when I click the button. 当我单击按钮时,事件确实触发。

According to the documentation 根据文档

This event is triggered when 1. the ShowFileDialog method has finished; 1. ShowFileDialog方法完成时触发此事件。 2. the method LoadImageEx has finished with IfShowFileDialog set to true. 2. LoadImageEx方法已将IfShowFileDialog设置为true。

EDIT : Some additional code to show how to save the file once the event gets fired. 编辑 :一些额外的代码来显示一旦事件被触发,如何保存文件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM