Google脚本-从text / html转换为application / pdf失败

问题描述 投票:1回答:1

我有一个具有简单逻辑的自定义Google脚本:它从电子表格中查找零件并构建内存HTML字符串,然后调用以下代码来生成PDF。

var blob = Utilities.newBlob(html_body, 'text/html').getAs('application/pdf').setName(pdf_name);

var newDoc = DriveApp.createFile(blob);

var pdf_url = newDoc.getUrl();

令人惊讶的是,对于相同的内容,它有时可以工作并随机返回错误:

从文本/ html转换为应用程序/ pdf失败。

我认为这种情况在较大的文件中最常见,因此我可能会遇到一些配额限制。

但是按照https://developers.google.com/apps-script/guides/services/quotas#current_limitations,任何限制都应引起相关信息。

https://developers.google.com/apps-script/reference/base/blob#getAs(String)周围的文档也没有任何说明。

有什么想法吗?

谢谢!

google-apps-script html-to-pdf
1个回答
0
投票

我有相同的问题,并且执行以下操作:

var html = HtmlService.createHtmlOutput(html_body);//This is now an object
html = html.getContent();//Get data as string - So its not an object or file
var blob = Utilities.newBlob(html,'application/pdf');//Create pdf from string

blob.setName(pdf_name);

就我而言,getAs('application/pdf')方法无法将Blob从文本文件转换为pdf文件。

© www.soinside.com 2019 - 2024. All rights reserved.