0

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.

Omid
  • 177
  • 2
  • 2
  • 10
  • 1
    See this [answer](https://stackoverflow.com/a/45211625/1553408) – Suhail Ansari Jun 26 '18 at 06:51
  • @SuhailAnsari I couldn't use the link you provided to modify my code because I am still a novice here. Could you please help me with the code? – Omid Jul 04 '18 at 06:20

0 Answers0