- You want to convert
var body=Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
as a PDF file.
- You want to put the created PDF file to the specific folder in Google Drive.
- You want to send the created PDF file as an attachment file.
- You want to retrieve the URL of created PDF file and return it to HTML side.
- Your question is unrelated to Spreadsheet.
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.
Modification points:
- In your case, I think that your goal can be achieved by modifying
submitData()
at Google Apps Script side.
- When the button is pushed, create a PDF data from
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.
Modified script:
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
}
Note:
- If you want to modify the style of PDF file, please modify
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.
- By the situation, it might be required to share the created PDF file.
References:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…