title: Google App Script - Save Spreadsheet to PDF saved on Google Drive
body: <p>I'm trying to save all of the sheets on my spreadsheet to google drive as one PDF (ultimately I would like to have them email as well). I'm having trouble saving more than just one of the sheets. I've tried multiple way of doing it. The code below is the best way I've found so far. Again the problem is that it only saves the first page as a PDF, I cant figure out how to get around the delete redundant sheets. All the posts I have seen only want to save 1 page, I have over 24 pages that need to be saved as one PDF. Thanks in advance for your help!</p>
  
  <pre><code>function PDF() {
    var sheetName = SpreadsheetApp.getActiveSpreadsheet();
    var folderID = "*** Google Drive ID***"; // Folder id to save in a Drive folder.
    var ss = SpreadsheetApp.openByUrl(
       'https://docs.google.com/spreadsheets/d/***Spreadsheet ID***'); 
    var pdfName = "MAR -  " + ss.getRange("A1:A1").getValue(); //Need to set the values to another sheet
  
    var sourceSpreadsheet = SpreadsheetApp.getActive();
    var sourceSheet = sourceSpreadsheet.getSheetByName(sheetName);
    var folder = DriveApp.getFolderById(folderID);
  
    //Copy whole spreadsheet
    var destSpreadsheet = SpreadsheetApp.open(DriveApp.getFileById(sourceSpreadsheet.getId()).makeCopy("tmp_convert_to_pdf", folder))
  
    //delete redundant sheets
    var sheets = destSpreadsheet.getSheets();
    for (i = 0; i &lt; sheets.length; i++) {
      if (sheets[i].getSheetName() != sheetName){
        destSpreadsheet.deleteSheet(sheets[i]);
      }
    }
    var destSheet = destSpreadsheet.getSheets()[0];
  
    //repace cell values with text (to avoid broken references) 
    var sourceRange = sourceSheet.getRange(1,1,sourceSheet.getMaxRows(),sourceSheet.getMaxColumns());
    var sourcevalues = sourceRange.getValues();
    var destRange = destSheet.getRange(1, 1, destSheet.getMaxRows(), destSheet.getMaxColumns());
    destRange.setValues(sourcevalues);
  
    //save to pdf
    var theBlob = destSpreadsheet.getBlob().getAs('application/pdf').setName(pdfName);
    var newFile = folder.createFile(theBlob);
  
    //Delete the temporary sheet
    DriveApp.getFileById(destSpreadsheet.getId()).setTrashed(true);
  }
  </code></pre>