首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >异常:从text/html到application/pdf的转换失败-从昨天开始

异常:从text/html到application/pdf的转换失败-从昨天开始
EN

Stack Overflow用户
提问于 2021-08-12 09:58:51
回答 1查看 125关注 0票数 0

我把我的电子邮件保存为PDF格式。它工作得很好。由于出现错误,它在过去几天内停止工作

异常:从text/html到application/pdf的转换失败

这里的某个人也报道了:

It just stopped working - google-app-script google-drive-api createFile

代码语言:javascript
复制
function saveGmailAsPDF() {

  var gmailLabels  = "TESTING";
  var driveFolder  = "TEST2";

  var threads = GmailApp.search("in:" + gmailLabels, 0, 5);

  if (threads.length > 0) {

    /* Google Drive folder where the Files would be saved */
    var folders = DriveApp.getFoldersByName(driveFolder);
    var folder = folders.hasNext() ?
        folders.next() : DriveApp.createFolder(driveFolder);

    /* Gmail Label that contains the queue */
    var label = GmailApp.getUserLabelByName(gmailLabels) ?
        GmailApp.getUserLabelByName(gmailLabels) : GmailApp.createLabel(driveFolder);

    for (var t=0; t<threads.length; t++) {

      //threads[t].removeLabel(label);
      var msgs = threads[t].getMessages();

      var html = "";
      var attachments = [];

      var subject = threads[t].getFirstMessageSubject();

      /* Append all the threads in a message in an HTML document */
      for (var m=0; m<msgs.length; m++) {

        var msg = msgs[m];

        html += "From: " + msg.getFrom() + "<br />";
        html += "To: " + msg.getTo() + "<br />";
        html += "Date: " + msg.getDate() + "<br />";
        html += "Subject: " + msg.getSubject() + "<br />";
        html += "<hr />";
        html += msg.getBody().replace(/<img[^>]*>/g,"");
        html += "<hr />";

        var atts = msg.getAttachments();
        for (var a=0; a<atts.length; a++) {
          attachments.push(atts[a]);
        }
      }

      /* Save the attachment files and create links in the document's footer */
      if (attachments.length > 0) {
        var footer = "<strong>Attachments:</strong><ul>";
        for (var z=0; z<attachments.length; z++) {
          var file = folder.createFile(attachments[z]);
          footer += "<li><a href='" + file.getUrl() + "'>" + file.getName() + "</a></li>";
        }
        html += footer + "</ul>";
      }

      /* Convert the Email Thread into a PDF File */


      //The PDF craeted is damaged by the below code
      //var blob = Utilities.newBlob(html, "application/pdf").setName("mail" + ".pdf");
      //var theFolderId = '{FOLDER ID}';
      //var parentFolder = DriveApp.getFolderById(theFolderId);
      //folder.createFile(blob);

      // PDF is damaged by the below code
      //var html = "<h1>Hello world</h1>";
      //var blob = Utilities.newBlob(html, "application/pdf", "text.pdf");
      //DriveApp.createFile(blob);


      //the below code was working well. 
      var tempFile = DriveApp.createFile("temp.html", html, "text/html");
      //the bellow line is giving the error for the last few days
      //Error : Exception: Conversion from text/html to application/pdf failed
      folder.createFile(tempFile.getAs("application/pdf")).setName(subject + ".pdf");
      tempFile.setTrashed(true);

    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2021-08-12 12:43:35

这似乎是一个持续的bug。似乎已经向Google Issue Tracker报告了。转到the issue并单击左上角的白色星号(☆) (就在问题ID的左侧)以提高其优先级。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68755288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档