Recipe
Turn a Google Form response into a PDF and email it
Each new form response becomes a PDF saved to Drive and emailed to the respondent, using the answers as a simple table.
Set it up
- Link the form to a spreadsheet, then open Extensions > Apps Script from that spreadsheet.
- Paste the script, set folderId in FP, and make sure one form question is titled Email.
- Triggers > Add trigger > onFormSubmit > From spreadsheet > On form submit. Approve the prompts.
The script
/**
* Turn each Google Form response into a PDF in Drive and email it to the respondent.
* Trigger: installable "On form submit" trigger on the response spreadsheet for onFormSubmit.
* The form must collect an email in a question titled "Email".
*/
var FP = { folderId: 'PASTE_FOLDER_ID', emailField: 'Email', title: 'Form response', subject: 'Your copy of your response' };
function escapeHtml_(s) {
return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
}
function onFormSubmit(e) {
if (!e || !e.namedValues) return 'skip:no-event';
var rows = Object.keys(e.namedValues).map(function (q) {
return '<tr><th align="left">' + escapeHtml_(q) + '</th><td>' + escapeHtml_(e.namedValues[q].join(', ')) + '</td></tr>';
});
var html = '<h1>' + escapeHtml_(FP.title) + '</h1><table border="1" cellpadding="6">' + rows.join('') + '</table>';
var stamp = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd HHmm');
var pdf = Utilities.newBlob(html, 'text/html', FP.title).getAs('application/pdf').setName(FP.title + ' ' + stamp + '.pdf');
DriveApp.getFolderById(FP.folderId).createFile(pdf);
var to = e.namedValues[FP.emailField] ? String(e.namedValues[FP.emailField][0]).trim() : '';
if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(to)) return 'saved:no-email';
MailApp.sendEmail({ to: to, subject: FP.subject, body: 'Your response is attached.', attachments: [pdf] });
return 'saved+sent';
}Test status. 4 of 4 automated checks pass, run Nov 2026 against simulated Google services. This recipe has not yet been run inside a live Google account. Test it on a copy of your sheet first.
What you should see
| Question | Answer |
|---|---|
| Name | Dana Ruiz |
| dana@example.com | |
| Request | Room booking, Dec 3 |
One response becomes one PDF. Sample values, not output from a real account.
Common errors and fixes
- TypeError: Cannot read properties of undefined (reading 'namedValues')
- You ran the function from the editor. Submit the form to fire it.
- The PDF is saved but no email arrives
- The question title must match emailField exactly.
- Exception: You do not have permission to call DriveApp.getFolderById
- Re-run the trigger authorization after changing scopes.
Permissions. Running this script asks you to grant Google permissions for the services listed above, to your own script. TriggerShelf never receives your Google data. See the permissions table. Google will show "Google hasn't verified this app"; that is expected for a script you paste yourself.
TriggerShelf is independent and not affiliated with or endorsed by Google LLC. Google Sheets, Gmail, Google Drive and Apps Script are trademarks of Google LLC. Quota figures come from Google's Apps Script quotas page. Test on a copy first.