使用HTML文件输出PDF [英] Using HTML file to output a PDF
问题描述
我的功能大部分都在运行 - 它创建文件,运行评估并获取内容,但实际上并未呈现html。它只是留下所有的html符号。
例如,它输出一个pdf,但它显示为:
亲爱的Martin,< br />
而非:
亲爱的Martin
如何确保呈现HTML以便PDF正确布局, t
以下是代码:
var docName =test;
var htmlBody = HtmlService.createHtmlOutput(template.evaluate()。getContent())。getContent()
var doc = DocumentApp.create(docName);
doc.appendParagraph(htmlBody);
doc.saveAndClose();
DocsList.createFile(doc.getAs('application / pdf'))。rename(docName);
您可以使用现有的HTML作为blob,将它转换为PDF格式如下:
var htmlBody = HtmlService.createHtmlOutputFromFile('my_file_within_script_project.html')。getContent();
var blob = Utilities.newBlob(htmlBody,'text / html')。getAs('application / pdf')。setName('my_output_in_drive.pdf');
DriveApp.createFile(blob);
So I've got a HTML file, that I am using to send emails, but in some instances I want it simply to use that file to create a PDF of the same template.
I've got it functioning for the most part - it creates the file, runs the evaluations and gets the content, but it doesn't actually render the html. It simply leaves all the html notation in place.
For example, it outputs a pdf but it reads:
Dear Martin, <br />
instead of:
Dear Martin
How do I make sure it renders the HTML so that the PDF is laid out correctly, and doesn't have the html code noted in the text?
Here's the code:
var docName = "test";
var htmlBody = HtmlService.createHtmlOutput(template.evaluate().getContent()).getContent()
var doc = DocumentApp.create(docName);
doc.appendParagraph(htmlBody);
doc.saveAndClose();
DocsList.createFile(doc.getAs('application/pdf')).rename(docName);
You can use your existing HTML as a blob, and convert it to PDF like this:
var htmlBody = HtmlService.createHtmlOutputFromFile('my_file_within_script_project.html').getContent();
var blob = Utilities.newBlob(htmlBody, 'text/html').getAs('application/pdf').setName('my_output_in_drive.pdf');
DriveApp.createFile(blob);
这篇关于使用HTML文件输出PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!