0

Hi I've got this script that I use to email a set of sheets as a PDF and it's working properly except for the margins I would need to be able to set the margins at 0.5 for the top 0.25 for the sides and 0.6 for the bottom here's my existing script

function createPDF() {
  var mainSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Main');
  var sheetNames = mainSheet.getRange('B3:B').getValues().flat().filter(String);
  var selectedSheets = sheetNames.filter(function(name, i) {
    return mainSheet.getRange(i+3, 1).getValue();
  });
  var sheetsToHide = [mainSheet];
  SpreadsheetApp.getActiveSpreadsheet().getSheets().forEach(function(sheet) {
    if (sheet.getName() !== 'Main' && sheet.getName() !== 'Template' && sheet.getName() !== 'Import' && selectedSheets.indexOf(sheet.getName()) === -1) {
      sheetsToHide.push(sheet);
    }
  });
  sheetsToHide.forEach(function(sheet) {
    sheet.hideSheet();
  });
  var blob = mainSheet.getParent().getAs('application/pdf');
  var file = DriveApp.createFile(blob).setName('PDF Report');
  GmailApp.sendEmail(Session.getActiveUser().getEmail(), "PDF Report", "", {attachments:[file]});
  file.setTrashed(true);
  sheetsToHide.forEach(function(sheet) {
    sheet.showSheet();
  });
  updateCheckboxes();
}

Thanks

Yvan L
  • 233
  • 3
  • 12
  • About `I would need to be able to set the margins at 0.5 for the top 0.25 for the sides and 0.6 for the bottom`, what is the unit of those values? And, I thought that this thread https://stackoverflow.com/q/46088042 , and these gists https://gist.github.com/andrewroberts/c37d45619d5661cab078be2a3f2fd2bb and https://gist.github.com/Spencer-Easton/78f9867a691e549c9c70 might be useful for achieving your goal. – Tanaike May 10 '23 at 01:07

0 Answers0