【问题标题】:Convert a closed google Doc to a PDF and attach it in an email将已关闭的 google Doc 转换为 PDF 并附加到电子邮件中
【发布时间】:2018-08-30 15:38:54
【问题描述】:

我有一个电子表格表单,它获取信息并将其放入文档中,然后需要将其转换为 pdf 并作为附件发送。

我已准备好文档“模板”,但不知道如何转换未作为选项卡打开的文档(也就是我无法使用 DocumentApp)。

任何想法将不胜感激。

【问题讨论】:

  • 使用 DriveApp 访问 Google Drive 中的文件。

标签: javascript google-apps-script google-docs google-sheets-api


【解决方案1】:

您可以从另一个脚本使用 DocumentApp,而不仅仅是绑定到文档的脚本。假设您的文档模板是文档 ID abcdefghijklmnop...

// If you have a template, first make a copy
var docCopy = DriveApp.getFileById('abcdefghijklmnop').makeCopy();
var copyId = docCopy.getId();
var doc = DocumentApp.openById(copyId);

// Do whatever you need to modify the doc here.

// Now we're done, and `doc` needs to turn into a PDF
var pdfContent = doc.getAs('application/pdf');
var draftMail = GmailApp.createDraft('william@example.com',
                                     'Email title', 'Pls see attached', 
                                     {
                                         attachments: [pdfContent.getAs(MimeType.PDF)],
                                         name: 'Converted doc content'
                                     });
// Now send the mail
draftMail.send();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 1970-01-01
    • 2012-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多