1
votes

I am using PDFTron to create a PDF Reader and I am trying to open PDF files that have been encrypted with the password "test". I am trying to make it so the user doesn't have to type the password in themselves in the password dialog box like below. Instead I would like to pass "test" in the code itself and then for it to open the document. I am handling security of the viewer in a different way so it isn't a problem me passing the password in the code itself. I have looked online and have tried it like below but it didn't work it just showed the dialog as normal.

Attempt

PDF Tron Password Dialog screen

Thanks

2

2 Answers

1
votes

To resolve the issue follow Ryan's answer. However if you are still having problems the way I did it was the following:

buttons: {
          'OK': {click: function() {
             if (!finishedPassword) {
                  tryingPassword = true;
                  passwordCallback("PUT YOUR PASSWORD HERE");
                }
                  $(this).dialog('close');
                },
                  id: 'pass_ok_button',
                  text: 'OK'
                },
          'Cancel': function() {
                  $(this).dialog('close');
                }
         }

Go to PDFReaderControl.js and find the above code (search for passwordCallback or buttons and you will see this bit of code). Change the value of passwordCallback to your password and then:

++(me.passwordTries);
document.getElementById("pass_ok_button").click();

Find the line ++(me.passwordTries); and on the next line paste in the click function for the pass_ok_button same as above.

And now the dialog box shouldn't appear and the password will automatically be provided by the program.

0
votes

You can add the following code to config.js to load a pdf document with a password instantly.

$(document).on('viewerLoaded', function() {
  readerControl.getPassword = function(callback) {
    callback('enter password here');
  };
});