Google app script on how to create a pdf from the data received from an html form of your spreadsheet and send the pdf file via email - I would like to create a pdf file fro
var body=Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
as a PDF file.I could understand like above. If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
submitData()
at Google Apps Script side.var body=Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
. And create the PDF data as the file.Please modify submitData()
as follows. Please set the folder ID to var folderId = "###"
.
function submitData(form) {
var subject='New Feedback';
var body=Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
var folderId = "###"; // Please set the folder ID. // Added
var blob = Utilities.newBlob(body, MimeType.HTML, form.name).getAs(MimeType.PDF); // Added
var file = DriveApp.getFolderById(folderId).createFile(blob); // Added
var aliases = GmailApp.getAliases()
Logger.log(aliases); //returns the list of aliases you own
Logger.log(aliases[0]); //returns the alias located at position 0 of the aliases array
GmailApp.sendEmail('my-email@my-email.com','From an alias', 'A message from an alias!', {'from': aliases[0],subject: subject,htmlBody: body, attachments: [blob]}); // Modified
return file.getUrl(); // Modified
}
name: %s <br />Email: %s<br />Comment: %s
of var body=Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
. You can use HTML in this case.