Email a Custom Sheets as PDF in Attachment

Script export and send email of custom sheet on PDF in Attachment for Google Sheets with GAS (Google Apps Script) & Javascript Language, don't forget to change the variables according to your goal, read tips and watch video to understand more about how to run it even you are not a programmer

How to use it 

  • Sheets you want to print :

you can add more inside the array

var wantedSheets=[' Sheet1','Sheet2','Sheet3'.....];

  • Print Options :

  • Email parameters :

Seperate each email with comma :

MailApp.sendEmail(',', 'Title', 'Body',...

The Code

Please Comment and help us with share !


  1. how can i send Pivot table on mail body and sheet-1 as attachment?

    1. The Above Question Is same here....
      Have you got an answer from anyone????

  2. Great Code! Super easy to follow!

  3. Was the best code.

  4. ADEL! You the MAN! Thank you, works perfect. A few question... how can you set page margins and page height/width?

  5. Hi, I think this solution is a little simpler: (But thank you for your kode)

    //Get Active Spreadsheet
    var spreadSheet=SpreadsheetApp.getActiveSpreadsheet();

    //Get Sheet to print of the spreadsheets
    var sheets=spreadSheet.getSheets();
    var mySheet = spreadSheet.getSheetByName("PrintSheet");
    var sheetID = mySheet.getSheetId();

    //Export URL with Parameters
    var spreadSheetId = spreadSheet.getId();
    var URL = ""+spreadSheetId+"/export"+
    //the HTTP method for the request: get and headers : authorization : Bearer tokens to access OAuth 2.0-protected resources
    var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};


Post a Comment

Popular posts from this blog

Export and Email Specific Range in Google Sheets in CSV,PDF or XLSX