Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Html模板未将格式或图像打印为pdf_Google Apps Script_Google Drive Api - Fatal编程技术网

Google apps script Html模板未将格式或图像打印为pdf

Google apps script Html模板未将格式或图像打印为pdf,google-apps-script,google-drive-api,Google Apps Script,Google Drive Api,我正在使用应用程序脚本中的html模板功能创建电子邮件草稿和pdf文档。所有的格式都显示在电子邮件中,但在pdf中,很多格式都丢失了 我的目标是在格式化的pdf和电子邮件中显示徽标。 我开始尝试包含一个图像,但失败了。我无法将图像作为现有模板的一部分显示在任何位置(尽管按照Google开发者信息,如果我仅将图像用作blob源,我可以将图像输入电子邮件/pdf,这意味着我不能包含任何其他内容) 我的下一个想法是直接在html文件中构建徽标。这失败了,因为我无法将背景颜色打印到pdf 我查看了谷歌的

我正在使用应用程序脚本中的html模板功能创建电子邮件草稿和pdf文档。所有的格式都显示在电子邮件中,但在pdf中,很多格式都丢失了

我的目标是在格式化的pdf和电子邮件中显示徽标。 我开始尝试包含一个图像,但失败了。我无法将图像作为现有模板的一部分显示在任何位置(尽管按照Google开发者信息,如果我仅将图像用作blob源,我可以将图像输入电子邮件/pdf,这意味着我不能包含任何其他内容)

我的下一个想法是直接在html文件中构建徽标。这失败了,因为我无法将背景颜色打印到pdf

我查看了谷歌的开发者部分和这里的q&as,也做了一些一般的网络搜索。 在阅读这些内容后,我检查了以下内容: 所有格式都是内联的。 在创建输出之前,将调用并评估模板。 图像是共享的

我是一个初学者,所以我一直在尝试一切,希望找到一个解决办法。我留下了一些不同的方法,你可以看看我尝试了什么

如果有人能说明我错在哪里,我将非常感激

服务器端代码

函数包括(文件名){
返回HtmlService.createHtmlOutFromFile(文件名)
.getContent();
}
函数getImageUrl(){
//这是我复制的编码为base64的代码,用于html img,但base64编码/解码不适合我。
//var album=GEThttps://photoslibrary.googleapis.com/v1/albums/{albumId};
var photosUrl=”https://photos.google.com/photo/AF1QipMkQrHJPYe935uC-Rap5qVqNaLdUs6rp38yVaw";
变量htmlImage=“”
var driveUrl=”https://drive.google.com/file/d/10OgwTmtVp5yDKHdC7P1K2KBEMuEbn6YW/view?usp=sharing";
var imgId=DriveApp.getFileById('10ogwtmtvp5ydkhdc7p1k2kbemubn6yw');
var imgType=imgId.getMimeType();
var imgPng=imgId.getAs('image/png');//图像为png
var imgBlob1=imgId.getBlob();//图像为blob
var imgHtml=UrlFetchApp.fetch(photourl.getContent();//图像格式为html
var tmpHtml=HtmlService.createTemplate(imgHtml);
var contHtml=tmpHtml.getRawContent();
Logger.log('imgType='+imgType+'\n imgBlob1='+imgBlob1);
//创建草稿并另存为pdf
var createDraft=函数myGet(){
var temp=HtmlService.createTemplateFromFile('text');
返回温度evaluate();
}
var draft=createDraft();
var content=draft.getContent();
var blob=Utilities.newBlob(content'text/html').getAs('application/pdf').setName('text for image');
DriveApp.createFile(blob);
//创建草稿电子邮件
var recipient=Session.getActiveUser().getEmail();
var主题=‘测试’;
var body='这是一个测试';
var options={htmlBody:content};
createDraft(收件人、主题、正文、选项);
}
CSS代码

正文{
颜色:蓝色;
}
HTML模板


包括来自带有img标记和url的驱动器的图像
1.

包含contHtml(模板化blob)
1

使用jquery包含脚本中的imgPng
1
2
3

在jquery中包含来自脚本的htmlImage 1
2
3

风格测试 标志

标题1 标题2 标题3 行数据
行数据
行数据 行数据
行数据
行数据

检查背景格式的其他文本
执行记录:
[18-06-2113:30:23:778]开始执行
[18-06-21 13:30:23:784 CEST]会话。getActiveUser()[0秒]
[18-06-21 13:30:23:784 CEST]User.getEmail()[0秒]
[18-06-21 13:30:23:926 CEST]GmailApp.getAlias()[0.14秒]
[18-06-21 13:30:23:928 CEST]Logger.log([[alias1,alias2,alias3],][])[0秒]
[18-06-21 13:30:24:047 CEST]DriveApp.getFileById([10OgwTmtVp5yDKHdC7P1K2KBEMuEbn6YW])[0.116秒]
[18-06-21 13:30:24:048 CEST]File.getMimeType()[0秒]
[18-06-21 13:30:24:049 CEST]File.getAs([image/png])[0.001秒]
[18-06-21 13:30:24:050 CEST]文件.getBlob()[0秒]
[18-06-21 13:30:24:148 CEST]UrlFetchApp.fetch([https://photos.google.com/photo/AF1QipMkQrHJPYe935uC-Rap5qVqNaLdUs6rp38yVaw])[0.097秒]
[18-06-21 13:30:24:157 CEST]HTTPResponse.getContent()[0.008秒]
[18-06-21 13:30:24:272 CEST]HtmlService.createTemplate([10,60,33,68,79,67,84,89,80,69,32104116109108,62,10,60104116109108,32108,97110103,61,34101110,34,62,10,32,60104101,97100,62,10,32,32,60109101116,97,32,99104,97114115101116,61]…)[0.002秒]
[18-06-21 13:30:24:273 CEST]函数。应用([[])[0秒]
[18-06-21 13:30:24:273 CEST]Logger.log([imgType=image/png
imgBlob1=Blob,[]])[0秒]
[18-06-21 13:30:24:276 CEST]HtmlService.createTemplateFromFile([text])[0.002秒]
[18-06-21 13:30:24:277 CEST]函数。应用([[])[0.001秒]
[18-06-21 13:30:24:278 CEST]HtmlService.createHtmlOutput()[0秒]
[18-06-21 13:30:24:280 CEST]HtmlOutput.append([
])[0秒]
[18-06-21 13:30:24:280 CEST]HtmlOutput.append([
使用强制打印jquery包含来自另一个文件的html样式
1])[0秒] [18-06-21 13:30:24:281 CEST]HtmlService.CreateHtmlOutFromFile([LogoStyles])[0秒] [18-06-21 13:30:24:281 CEST]HtmlOutput.getContent()[0秒] [18-06-21 13:30:24:282 CEST]HtmlOutput.append([

])[0秒] [18-06-21 13:30:24:283 CEST]HtmlOutput.append([ 使用jquery从脚本中包括imgBlob1
1])[0秒] [18-06-21 13:30:24:284 CEST]HtmlOutput.appendUntrusted([Blob])[0秒] [18-06-21 13:30:24:284 CEST]HtmlOutput.append([
])[0秒] [18-06-21 13:30:24:285 CEST]HtmlOutput.append([
将脚本中的imgBlob1包含在img中
Execution transcript:

[18-06-21 13:30:23:778 CEST] Starting execution
[18-06-21 13:30:23:784 CEST] Session.getActiveUser() [0 seconds]
[18-06-21 13:30:23:784 CEST] User.getEmail() [0 seconds]
[18-06-21 13:30:23:926 CEST] GmailApp.getAliases() [0.14 seconds]
[18-06-21 13:30:23:928 CEST] Logger.log([[alias1, alias2, alias3], []]) [0 seconds]
[18-06-21 13:30:24:047 CEST] DriveApp.getFileById([10OgwTmtVp5yDKHdC7P1K2KBEMuEbn6YW]) [0.116 seconds]
[18-06-21 13:30:24:048 CEST] File.getMimeType() [0 seconds]
[18-06-21 13:30:24:049 CEST] File.getAs([image/png]) [0.001 seconds]
[18-06-21 13:30:24:050 CEST] File.getBlob() [0 seconds]
[18-06-21 13:30:24:148 CEST] UrlFetchApp.fetch([https://photos.google.com/photo/AF1QipMkQrHJPYe935uC-Rap5qVqNaLdUs6rp38yVaw]) [0.097 seconds]
[18-06-21 13:30:24:157 CEST] HTTPResponse.getContent() [0.008 seconds]
[18-06-21 13:30:24:272 CEST] HtmlService.createTemplate([10,60,33,68,79,67,84,89,80,69,32,104,116,109,108,62,10,60,104,116,109,108,32,108,97,110,103,61,34,101,110,34,62,10,32,32,60,104,101,97,100,62,10,32,32,60,109,101,116,97,32,99,104,97,114,115,101,116,61]...) [0.002 seconds]
[18-06-21 13:30:24:273 CEST] Function.apply([[]]) [0 seconds]
[18-06-21 13:30:24:273 CEST] Logger.log([imgType = image/png
 imgBlob1  = Blob, []]) [0 seconds]
[18-06-21 13:30:24:276 CEST] HtmlService.createTemplateFromFile([text]) [0.002 seconds]
[18-06-21 13:30:24:277 CEST] Function.apply([[]]) [0.001 seconds]
[18-06-21 13:30:24:278 CEST] HtmlService.createHtmlOutput() [0 seconds]
[18-06-21 13:30:24:280 CEST] HtmlOutput.append([<!DOCTYPE html>
]) [0 seconds]
[18-06-21 13:30:24:280 CEST] HtmlOutput.append([<html>

  <head>
    <base target="_top">
  include styles html from another file with forced printing jquery <br>
  1 ]) [0 seconds]
[18-06-21 13:30:24:281 CEST] HtmlService.createHtmlOutputFromFile([LogoStyles]) [0 seconds]
[18-06-21 13:30:24:281 CEST] HtmlOutput.getContent() [0 seconds]
[18-06-21 13:30:24:282 CEST] HtmlOutput.append([ <br> <br>
]) [0 seconds]
[18-06-21 13:30:24:283 CEST] HtmlOutput.append([  </head>

  <body style="Background: white;"> 
  include imgBlob1 from script with jquery <br>
  1 ]) [0 seconds]
[18-06-21 13:30:24:284 CEST] HtmlOutput.appendUntrusted([Blob]) [0 seconds]
[18-06-21 13:30:24:284 CEST] HtmlOutput.append([  <br>
]) [0 seconds]
[18-06-21 13:30:24:285 CEST] HtmlOutput.append([  <br>
  include imgBlob1 from script with img tags <br>
  1 <img src=imgBlob1 />
  <br>
  <br>
  include image from Drive with img tags and url<br>
  1 <img src="https://drive.google.com/uc?export=do]...) [0 seconds]
[18-06-21 13:30:24:286 CEST] HtmlOutput.append([<br>
]) [0 seconds]
[18-06-21 13:30:24:287 CEST] HtmlOutput.append([  <br>
  include imgPng from script with jquery<br>
  1 ]) [0 seconds]
[18-06-21 13:30:24:288 CEST] HtmlOutput.append([<br>
]) [0 seconds]
[18-06-21 13:30:24:288 CEST] HtmlOutput.append([  2 ]) [0 seconds]
[18-06-21 13:30:24:289 CEST] HtmlOutput.append([<br>
]) [0 seconds]
[18-06-21 13:30:24:290 CEST] HtmlOutput.append([  3 ]) [0 seconds]
[18-06-21 13:30:24:291 CEST] HtmlOutput.appendUntrusted([Blob]) [0 seconds]
[18-06-21 13:30:24:291 CEST] HtmlOutput.append([<br>
]) [0 seconds]
[18-06-21 13:30:24:292 CEST] HtmlOutput.append([  <br>
  include htmlImage from script with jquery
  1 ]) [0 seconds]
[18-06-21 13:30:24:293 CEST] HtmlOutput.append([<br>
]) [0 seconds]
[18-06-21 13:30:24:294 CEST] HtmlOutput.append([  2 ]) [0 seconds]
[18-06-21 13:30:24:295 CEST] HtmlOutput.append([<br>
]) [0 seconds]
[18-06-21 13:30:24:295 CEST] HtmlOutput.append([  3 ]) [0 seconds]
[18-06-21 13:30:24:296 CEST] HtmlOutput.appendUntrusted([<img src="data:image/pgn; base64,https://photos.google.com/photo/AF1QipMkQrHJPYe935uC-Rap5qVqNaLdUs6rp38yVaw" />]) [0 seconds]
[18-06-21 13:30:24:297 CEST] HtmlOutput.append([<br>
]) [0 seconds]
[18-06-21 13:30:24:298 CEST] HtmlOutput.append([  <br>
test for style  
    <table style="background:#ddea95";>
      <tr>
        <th style="border: solid chartreuse; padding:5px; width: 150px; height: 150px;">Logo</th>
      </tr>
    </table>
<b]...) [0 seconds]
[18-06-21 13:30:24:299 CEST] HtmlOutput.append([]) [0 seconds]
[18-06-21 13:30:24:299 CEST] HtmlOutput.getContent() [0 seconds]
[18-06-21 13:30:24:301 CEST] Utilities.newBlob([<!DOCTYPE html>
<html>

  <head>
    <base target="_top">
  include styles html from another file with forced printing jquery <br>
  1  <br> <br>
  </head>

  <body style="Background: white;"> 
  in, ]...) [0 seconds]
[18-06-21 13:30:24:302 CEST] Blob.getAs([application/pdf]) [0 seconds]
[18-06-21 13:30:24:302 CEST] Blob.setName([text for image]) [0 seconds]
[18-06-21 13:30:24:304 CEST] Blob.getName() [0 seconds]
[18-06-21 13:30:24:304 CEST] Blob.getContentType() [0 seconds]
[18-06-21 13:30:25:202 CEST] DriveApp.createFile([Blob]) [0.899 seconds]
[18-06-21 13:30:25:203 CEST] Session.getActiveUser() [0 seconds]
[18-06-21 13:30:25:203 CEST] User.getEmail() [0 seconds]
[18-06-21 13:30:25:405 CEST] GmailApp.createDraft([alias1, test, this is a test, {htmlBody=<!DOCTYPE html>
<html>

  <head>
    <base target="_top">
  include styles html from another file with forced printing jquery <br>
  }]...) [0.201 seconds]
[18-06-21 13:30:25:408 CEST] Execution succeeded [1.477 seconds total runtime]