【问题标题】:How Convert Google Doc to PDF when send google doc as in html format以html格式发送谷歌文档时如何将谷歌文档转换为PDF
【发布时间】:2020-10-06 07:48:07
【问题描述】:

如何通过 Google Script 将 Google Doc 转换为 PDF 需要在下面的脚本中进行哪些更改:

\\

function docToHtml(docUrl) {
  let docId = DocumentApp.openByUrl(docUrl).getId();
  return UrlFetchApp.fetch(
    `https://docs.google.com/feeds/download/documents/export/Export?id=${docId}&exportFormat=html`,
    {
      method: 'GET',
      headers: {'Authorization': `Bearer ${ScriptApp.getOAuthToken()}`},
      muteHttpExceptions: true,
    },
  ).getContentText();
}

\\

【问题讨论】:

    标签: google-apps-script google-sheets google-cloud-platform google-docs


    【解决方案1】:

    您可以使用下面的 sn-p 来获取 Google Doc 的 PDF:

    
    function exportPDF() {
      var theDoc = DocumentApp.openById('DOCUMENT_ID').getAs('application/pdf');
      DriveApp.createFile(theDoc);
    }
    

    参考

    【讨论】:

    • 当文档通过邮件发送时显示此文本而不是附件 pdf %PDF-1.5 %���� 2 0 obj > endobj 3 0 obj > /W [ 1 3 1 ] /Index [ 2 16 ] /Info 12 0 R /Root 4 0 R /Size 18 /Prev 72277 /ID [] >> 流 x�cbd�gb``8 "�ր�F��L�
    • 您到底想达到什么目的?您是否尝试将 PDF 文件作为电子邮件附件发送? @sagar16
    • 如果是这种情况,您可以简单地从 Drive @sagar16 附加新创建的 PDF 文件
    • 我创建了一个 google doc 文件,它从 google sheet 中获取价值,在通过邮件发送这个 doc 时,我将此 doc 转换为 html 模板格式,现在我想以附件 pdf 格式而不是 html 发送这个 doc模板格式,那我们怎么做呢?
    • 将文档保存为驱动器中的 PDF,如上所述,然后附加驱动器中的 PDF @sagar16
    猜你喜欢
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多