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.
JS Code is here:
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 added a button next to the Scan button on online_demo_scan.html
<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
function Dynamsoft_OnGetFilePath(bSave, count, index, path, name) { alert('OnGetFilePath event fired!'); }
And the event does fire when I click the button.
According to the documentation
EDIT : Some additional code to show how to save the file once the event gets fired.