title: How to access a password protected PDF file on Google Drive using Apps Script
body: <p>I receive a bill monthly through email which is a password protected PDF file. The file always has the same password. I'm ultimately trying to use Google Apps Scripts (and Drive API) to take the file from Gmail, save it onto my Drive using OCR, to then save that to a separate document which I can take the text from and further use it in my script.</p>
  
  <p>I have simplified my use case here just trying to save the file to the Drive and access it through the script but I can't access it programatically as there doesn't seem to be a way to pass in a password.</p>
  
  <pre><code>for (var x in threads) {      
    var messages = threads[x].getMessages();
    for (var y in messages) {
    var from = messages[y].getFrom().slice(messages[y].getFrom().indexOf('&lt;')+1, messages[y].getFrom().indexOf('&gt;'));          
    if (from == 'EMAIL-GOES-HERE') {
      var attachment = messages[y].getAttachments()[0];
      var blob = attachment.getAs(MimeType.PDF);
      var resource = {title: blob.getName(), mimeType: blob.getContentType()};
      var file = Drive.Files.insert(resource, blob);
      var doc = DocumentApp.openById(file.id);
      ...
  </code></pre>
  
  <p>I'm expecting to be able to access the file by passing in the known password; however, since I can't send a password I receive the error: "The document is inaccessible. Please try again later."</p>