I am using the following code to generate a pdf based on a google sheet and then send it as an email attachment.
function emailReport() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName("Students"));
var subject = spreadsheet.getRange("U1:U1").getValues();
var emailTo = spreadsheet.getRange("V1:V1").getValues();
var message = spreadsheet.getRange("W1:W1").getValues();
var fileName = spreadsheet.getRange("X1:X1").getValues();
var ui = SpreadsheetApp.getUi();
var response = ui.alert("Do you want to send the report to this email?",emailTo, Browser.Buttons.YES_NO);
if (response == ui.Button.YES) {
readyForExport();
var pdf = DriveApp.getFileById(spreadsheet.getId()).getAs('application/pdf').getBytes();
var attach = {fileName:fileName[0][0],content:pdf, mimeType:'application/pdf'};
MailApp.sendEmail(emailTo, subject, message, {attachments:[attach]});
ui.alert("The report was successfully sent to "+emailTo+".");
} else {
ui.alert("The report was not sent.");
}
};
The problem is that the page orientation of my generated pdf is portrait. I want to have a pdf which is generated in landscape mode and I would also like to set the page size to A4.
Can anybody help?
Lots of thanks in advance.