Skip to content
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

Password filled programmatically #762

Closed
lillogoal opened this issue Sep 9, 2021 · 12 comments
Closed

Password filled programmatically #762

lillogoal opened this issue Sep 9, 2021 · 12 comments
Labels
core enhancement New feature or request
Milestone

Comments

@lillogoal
Copy link

lillogoal commented Sep 9, 2021

I have a question about protected pdf. I uploaded a pdf with password in viewer and it asked to me password.
Can i fill this form and submit programmatically, for example automatically onPdfLoaded ?

Thanks

@phuocng phuocng added core enhancement New feature or request labels Sep 11, 2021
@phuocng
Copy link
Member

phuocng commented Sep 11, 2021

Currently, it's not possible. But I will think about supporting it. Thanks for the suggestion.

@lillogoal
Copy link
Author

Thanks. Can i fork or make new pull request? How to do ?

@phuocng
Copy link
Member

phuocng commented Sep 11, 2021

I am sorry, it doesn't accept PRs because it's a commercial product.
Can you give me the idea of how you can pass the password?

@lillogoal
Copy link
Author

Ok ok thanks to reply. Have you assigned an id or input ref to textfield where user have to type password ? And button?

Sorry for my question but before buy library i Need to understand

@phuocng
Copy link
Member

phuocng commented Sep 11, 2021

There's no id. Here is the structure of html:

<div class="rpv-core__asking-password-body">
    <div class="rpv-core__asking-password-input rpv-core__asking-password-input--ltr">
        <input aria-label="" class="rpv-core__textbox" placeholder="" type="password" value="">
    </div>
    <button class="rpv-core__primary-button" type="button">Submit</button>
</div>

As I imagine, you can use querySelector to access the main input and/or the submit button.

@lillogoal
Copy link
Author

Yes i Will try.
When do you render these fields? Do you show these After call "onDocumentLoad"?

@lillogoal
Copy link
Author

Ok i tested with Javascript console. And it works. Exist a callback that called when password dialog/page prompts to user ?

This is the code:

const input = document.querySelector('.rpv-core__textbox');

Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set.call(input, "pippo");

document.querySelector('.rpv-core__primary-button').click();

@phuocng
Copy link
Member

phuocng commented Sep 12, 2021

@lillogoal
The feature was implemented in the latest code. In the next v2.9.0 version, you can do something as following:

const handleAskPassword = (e: DocumentAskPasswordEvent) => {
    e.verifyPassword('The password here');
};

<Viewer onDocumentAskPassword={handleAskPassword} />;

You don't have to set the input value and submit button manually.

@lillogoal
Copy link
Author

Thanks ♥️ do you want close ? When do you deploy ? Thanks

@phuocng
Copy link
Member

phuocng commented Sep 13, 2021

@lillogoal The v2.9.0 is released.
I also added a live example for your use case
https://react-pdf-viewer.dev/examples/submit-the-password-programmatically/

Let me know when you make the purchase ♥️

@lillogoal
Copy link
Author

no words only thanks. I have already written to my PM and in this week CEO is going to buy license

@phuocng
Copy link
Member

phuocng commented Sep 13, 2021

Awesome! Let me know if you have any questions or suggestions, so I can make the library better.

@phuocng phuocng closed this as completed Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants