0

So far i have gotten the Code below to work the way i would like it to but i just want to send the PFD as a Landscape, I understand that the Landscape thing have been posted before but i can not get them to work can anyone help?

Thanks,

function onOpen() {  
var submenu = [{name:"Email Sheet", functionName:"exportActiveSheets"}];
  SpreadsheetApp.getActiveSpreadsheet().addMenu('Email Script', submenu);  
}

function exportActiveSheets() {  
  // Set the Active Spreadsheet 
  var originalSpreadsheet = SpreadsheetApp.getActive();

  // Set the message to attach to the email.  
  var message = "Please see attached"; 

  // Get Project Name from Cell A1  
  var projectname = originalSpreadsheet.getRange("D2:Q2").getValues();  
  // Get Reporting Period from Cell B3  
  var period = originalSpreadsheet.getRange("D2:D2").getValues();  
  // Construct the Subject Line  
  //var subject = projectname";  
  var subject = "Press Production Run's for Tonight";

  // Get email details from "List" sheet and construct To: Header  
  var contacts = originalSpreadsheet.getSheetByName("List");  
  var numRows = contacts.getLastRow();  
  var emailTo = contacts.getRange(3, 2, numRows, 1).getValues();

  // Create a new Spreadsheet and copy the current sheet into it.  
  var newSpreadsheet = SpreadsheetApp.create("Spreadsheet to export");  
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();  
  var projectname = SpreadsheetApp.getActiveSpreadsheet();  
  sheet = originalSpreadsheet.getActiveSheet();  
  sheet.copyTo(newSpreadsheet);

  // Find and delete the default "Sheet 1", after the copy 
  newSpreadsheet.getSheetByName('Sheet1').activate();  
  newSpreadsheet.deleteActiveSheet();

  // Make PDF  
  var pdf = DriveApp.getFileById(newSpreadsheet.getId()).getAs('application/pdf').getBytes();'
  var attach = {fileName:'Tonights Jobs.pdf',content:pdf, mimeType:'application/pdf'};

  // Send the freshly constructed email  
  MailApp.sendEmail(emailTo, subject, message, {attachments:[attach]});

  // Delete temp sheet  
  DriveApp.getFileById(newSpreadsheet.getId()).setTrashed(true);  
}
  • Have you looked [here](https://stackoverflow.com/questions/26150732/creating-pdf-in-landscape-google-apps-script) or [here](https://stackoverflow.com/questions/45209619/google-apps-script-getasapplication-pdf-layout/45211625#45211625) – Cooper Aug 13 '19 at 23:05
  • Instead of getting the spreadsheet as pdf, you need to export it with the `UrlFetchApp`, and attach to your email the fetch response as a blob - just like done in the first solution referred by Cooper. – ziganotschka Aug 14 '19 at 08:28

0 Answers0