Skip to content

Instantly share code, notes, and snippets.

@DimuDesigns
Last active January 27, 2018 18:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save DimuDesigns/10fc19f9fee2e2f8d64aca5c37431abe to your computer and use it in GitHub Desktop.
Save DimuDesigns/10fc19f9fee2e2f8d64aca5c37431abe to your computer and use it in GitHub Desktop.
Apps Script PDF Export & Email
var spreadsheetId = "SPREADSHEET_ID",
sheetID = "SHEET_ID",
respondentEmail = "RESPONDENT_EMAIL";
var response = UrlFetchApp.fetch(
"https://docs.google.com/spreadsheets/d/" + spreadsheetId + "/export?" +
"format=pdf" +
"&size=2" +
"&fzr=true" +
"&portrait=false" + // you can change this to true for portrait mode
"&fitw=true" +
"&gid=" + sheetID +
"&gridlines=false" +
"&printtitle=false" +
"&sheetnames=false" +
"&attachment=true"
);
var pdf = response.getAs('application/pdf');
pdf.setName("your_file_name.pdf");
MailApp.sendEmail(
{
"to":respondentEmail,
"subject":"Subject text",
"htmlBody":"Body text",
"attachments":[pdf]
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment