【发布时间】:2021-04-04 13:15:18
【问题描述】:
我无权访问DriveApp,但我正在尝试通过电子邮件发送新创建文档的 PDF:
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'
});
然而,收到的 PDF 附件是一个空白文档,我认为这是因为在将内容添加到文档之前,该文档已作为 PDF 文件“获取”。
Google Apps 脚本有什么办法:
等到内容添加完毕后再转换为 PDF?
确保
getAs()使用doc的“刷新”版本(包含所有添加的内容)?
【问题讨论】: