I created PDF files protected with password. They are uploaded to Drupal and the password is saved in a field pdf_password in Drupal.

I would like the PDF to open them with pdf.js without having to ask for the password. For this I need to get the value of the field password pdf_password in the file libraries/pdf.js/web/viewer.js: instead of 123 to get the value of the field password pdf_password :

parameters.password = '123';

(the pdf.js is pdf.js project by Mozilla)

  • You might as well remove the password if you're going to make it available to anyone using the browser – Clive Sep 17 '19 at 9:52
  • I won't have it available to the public I want the pdf to open in the page but should be password protected when downloaded – user1619177 Sep 17 '19 at 15:31
  • You realise that any slightly-competent user would be able to just look at your javascript file and get the password though, right? – Clive Sep 17 '19 at 15:42
  • that is why I don't want to write there the password but <?php $pass= field_get_items('node', $node, $pdf_password); ?>and in the javascript file: <script type="text/javascript"> parameters.password = '<?php print $pass?>'; </script> – user1619177 Sep 17 '19 at 17:10
  • Yep, which anyone will be able to read, because it’s in a JavaScript file – Clive Sep 17 '19 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.