TriggerShelf

Recipe

Turn a Google Form response into a PDF and email it

Trigger: Installable on form submitServices: DriveApp, MailApp, UtilitiesMock-tested: Nov 2026

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

  1. Link the form to a spreadsheet, then open Extensions > Apps Script from that spreadsheet.
  2. Paste the script, set folderId in FP, and make sure one form question is titled Email.
  3. 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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

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

QuestionAnswer
NameDana Ruiz
Emaildana@example.com
RequestRoom 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.