title: Google apps script: Create a new document and send it using Gmail
body: <p>I would like to create a document and then send it using Gmail. Here is my code:</p>
  
  <pre><code>function myFunction() {
  var doc = DocumentApp.create('My document');
  doc.getBody().appendParagraph('This is the file that i want to receive');
  var file = DriveApp.getFileById(doc.getId());
  GmailApp.sendEmail('address@gmail.com', 'Attachment example', 'Please see the attached        file.', {attachments: [file.getAs(MimeType.PDF)],name: 'Automatic Emailer Script'
   });
  }
  </code></pre>
  
  <p>The file was created in my Google drive with the appended paragraph, the file id in doc.getId() is correct (using Logger.log() function). The problem is I <strong>always receive a blank pdf</strong> instead. I only could get the correct pdf file when change the code to manually input the file id in the :
  file = DriveApp.getFileById('1b-XpCUmmn020Vav6psp4aZnenyzyVCm6tcj1-TlvWyU');</p>
  
  <p>What did i do wrong in the code? Thank you very much for your responses!</p>