-
-
Notifications
You must be signed in to change notification settings - Fork 878
-
-
Notifications
You must be signed in to change notification settings - Fork 878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prompt for password for password protected PDF keeps popping up #581
Comments
you can define a custom password behavior using |
Yeah, the default If you want to cancel loading the file if the user presses "Cancel" on password prompt and do something with it, do something like this: function onPassword(callback, reason) {
function callbackProxy(password) {
// Cancel button handler
if (password === null) {
// Reset your `document` in `state`, un-mount your `<Document />`, show custom message, whatever
}
callback(password);
}
switch (reason) {
case PasswordResponses.NEED_PASSWORD: {
const password = prompt('Enter the password to open this PDF file.');
callbackProxy(password);
break;
}
case PasswordResponses.INCORRECT_PASSWORD: {
const password = prompt('Invalid password. Please try again.');
callbackProxy(password);
break;
}
default:
}
} |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Looks like you confused the repositories. This is React-PDF which is used to display PDFs. |
Hello, I have a problem when I try to close the alert, it is not allowed, I could give a clear example of how to close it when they give it to cancel |
@sebastam97 It is allowed, but you need to handle that like described in #581 (comment). |
@wojtekmaj I have a scenario where I want to check whether the password given by the user is correct or not. If it is correct, onLoadSuccess has to be called else need to throw an error which led to invoke onLoadError() method. Currently, I pass the password from API to the password callback and the document gets loaded if it is correct. But, not throwing an error when it becomes wrong. How can i handle this problem ? |
Hi @wojtekmaj
thanks |
@hilmanski Sure, it's open source :P Lines 347 to 363 in c2012f8
|
thanks for pointing out the file @wojtekmaj |
sometime the above solution code gives error, at that point this code is working:- visit #581 (comment) for more reference. |
@wojtekmaj Where does the |
Well that's really stupid - would you mind raising a PR for that? |
@wojtekmaj Sure thing, will open a PR now. Seems like the |
|
@atologistChiragRathod PasswordResponses is exported from react-pdf since #1615 (v7.4.1 and up). |
Hi @wojtekmaj good day i have a pdf file with password protected, but when the prompt box shows up i cant close it.
The text was updated successfully, but these errors were encountered: