You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -35,7 +56,7 @@ function loadProtectedPdf(path, password) {
35
56
console.log("PDF loaded successfully.");
36
57
},
37
58
function (errorCode, errorString) {
38
-
if (errorCode!==-1119) {
59
+
if (!isPasswordRequired(errorCode, errorString)) {
39
60
console.error(errorCode, errorString);
40
61
return;
41
62
}
@@ -52,20 +73,35 @@ function loadProtectedPdf(path, password) {
52
73
}
53
74
```
54
75
55
-
### For drag-and-drop files
76
+
### Drag-and-drop workflow (`OnPostLoad`)
56
77
57
-
You can detect load failures in [`OnPostLoad`](/_articles/info/api/WebTwain_IO.md#onpostload)by checking`DWTObject.ErrorCode`and`DWTObject.ErrorString`.
78
+
Use [`OnPostLoad`](/_articles/info/api/WebTwain_IO.md#onpostload)and check`DWTObject.ErrorCode`/`DWTObject.ErrorString`.
58
79
59
80
```javascript
60
81
DWTObject.RegisterEvent("OnPostLoad", function (path, name, type) {
61
-
if (DWTObject.ErrorCode===-1119) {
62
-
console.log(DWTObject.ErrorString);
63
-
// Add your own password prompt flow here.
82
+
if (!isPasswordRequired(DWTObject.ErrorCode, DWTObject.ErrorString)) return;
83
+
84
+
var userPassword =window.prompt(
85
+
"This PDF is password-protected. Please enter the password:",
alert("Password saved. Please drag and drop the file again.");
94
+
return;
64
95
}
96
+
97
+
var fullPath = path +"\\"+ name;
98
+
loadProtectedPdf(fullPath, userPassword);
65
99
});
66
100
```
67
101
68
102
> [!NOTE]
69
-
> In `OnPostLoad`, `path` is empty for drag-and-drop files.
70
-
> If you need a retry flow after entering a password, prompt the user to select the file again
71
-
> (for example, by using [`ShowFileDialog()`](/_articles/info/api/WebTwain_IO.md#showfiledialog) + [`LoadImageEx()`](/_articles/info/api/WebTwain_IO.md#loadimageex)).
103
+
> `-1119` can represent multiple PDF load issues, so do not use it alone.
104
+
> Starting in Dynamic Web TWAIN 19.4, encrypted-PDF load failures will use `-1120`.
105
+
>
106
+
> In `OnPostLoad`, `path` is empty for drag-and-drop files, so the code cannot directly retry with a file path.
107
+
> In this case, prompt for password, save it with `SetReaderOptions()`, and ask the user to drag and drop the file again.
0 commit comments