Using HTML file to output a PDF

前端 未结 2 1206
既然无缘
既然无缘 2021-01-15 15:14

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 i

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-15 16:06

    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);
    

提交回复
热议问题