Skip to content

Commit 8cfd84d

Browse files
committed
docs(faq): add password-protected PDF loading guidance
1 parent e002ddb commit 8cfd84d

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

_articles/faq/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ description: Dynamic Web TWAIN SDK Documentation FAQ
142142
8. [How can I separate my documents automatically by barcode?](/_articles/faq/separate-documents-by-barcode.md)
143143
9. [Is there any way to speed up the barcode reading process?](/_articles/faq/speed-up-barcode-reading-process.md)
144144
10. [What types of webcams does the Webcam Capture addon support](/_articles/faq/webcam-supported-by-webcam-capture-addon.md)
145+
11. [How can I prompt users for a password when loading a password-protected PDF?](/_articles/faq/prompt-password-for-protected-pdf.md)
145146

146147
## Project Deployment and End-user Installation
147148

@@ -228,4 +229,4 @@ description: Dynamic Web TWAIN SDK Documentation FAQ
228229

229230
## Annotation
230231

231-
1. [How can I add annotations to an image and then save/upload it?](/_articles/faq/dwt-with-annotation.md)
232+
1. [How can I add annotations to an image and then save/upload it?](/_articles/faq/dwt-with-annotation.md)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
layout: default-layout
3+
noTitleIndex: true
4+
needAutoGenerateSidebar: true
5+
title: How can I prompt users for a password when loading a password-protected PDF?
6+
keywords: Dynamic Web TWAIN, Addon, PDF, password, encrypted, LoadImageEx, OnPostLoad
7+
breadcrumbText: How can I prompt users for a password when loading a password-protected PDF?
8+
description: How can I prompt users for a password when loading a password-protected PDF?
9+
date: 2026-04-09 10:00:00 +0800
10+
last_modified: 2026-04-09 10:00:00 +0800
11+
---
12+
13+
# Addon
14+
15+
## How can I prompt users for a password when loading a password-protected PDF?
16+
17+
Dynamic Web TWAIN does not provide a built-in password prompt UI for encrypted PDFs.
18+
You need to implement your own prompt flow in application code.
19+
20+
### Recommended flow for `LoadImage()` / `LoadImageEx()`
21+
22+
1. Call [`LoadImage()`](/_articles/info/api/WebTwain_IO.md#loadimage) or [`LoadImageEx()`](/_articles/info/api/WebTwain_IO.md#loadimageex).
23+
2. In the failure callback, check whether `errorCode` is `-1119`.
24+
3. Prompt the user for a password.
25+
4. Call [`SetReaderOptions()`](/_articles/info/api/Addon_PDF.md#setreaderoptions) with that password.
26+
5. Retry loading the same PDF.
27+
28+
```javascript
29+
function loadProtectedPdf(path, password) {
30+
DWTObject.Addon.PDF.SetReaderOptions({ password: password || "" });
31+
DWTObject.LoadImageEx(
32+
path,
33+
Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
34+
function () {
35+
console.log("PDF loaded successfully.");
36+
},
37+
function (errorCode, errorString) {
38+
if (errorCode !== -1119) {
39+
console.error(errorCode, errorString);
40+
return;
41+
}
42+
43+
var userPassword = window.prompt(
44+
"This PDF is password-protected. Please enter the password:",
45+
"",
46+
);
47+
if (!userPassword) return;
48+
49+
loadProtectedPdf(path, userPassword);
50+
},
51+
);
52+
}
53+
```
54+
55+
### For drag-and-drop files
56+
57+
You can detect load failures in [`OnPostLoad`](/_articles/info/api/WebTwain_IO.md#onpostload) by checking `DWTObject.ErrorCode` and `DWTObject.ErrorString`.
58+
59+
```javascript
60+
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.
64+
}
65+
});
66+
```
67+
68+
> [!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)).

0 commit comments

Comments
 (0)