I don't have access to DriveApp
but am trying to email a PDF of a newly created document with:
var doc = DocumentApp.create('Sample Document');
var body = doc.getBody();
// create lots of content in the document...
//
// after adding all the content and applying styles etc
// send the document as PDF to the user
var pdf_file = doc.getAs("application/pdf");
GmailApp.sendEmail('user@test.com', 'Attachment example', 'Please see the attached file.', {
attachments: [pdf_file],
name: 'Test Name'
});
The PDF attachment received, however, is a blank document and I think this is because the document is being "got" as a PDF file before the contents have been added to the document.
Is there any way for Google Apps Script to either:
Wait until the content has been added before converting to PDF?
Ensure that
getAs()
uses a "refreshed" version ofdoc
(that has all the added contents)?