This can be super useful: How to create a PDF in your Google Drive of a specific sheet.
Important notes:
• The token is necessary ie var token = ScriptApp.getOAuthToken();
• All the parameters can be changed to suit your needs
Sheet (to copy)
https://docs.google.com/spreadsheets/…
Script:
function makePDF() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var token = ScriptApp.getOAuthToken();
var sheet = ss.getSheetByName(“Sheet1”);
var url = “https://docs.google.com/spreadsheets/…”.replace(“SS_ID”, ss.getId());
var folderID = “put your folder ID here”; // Folder id to save in a folder.
var folder = DriveApp.getFolderById(folderID);
var invoiceNumber = ss.getRange(“E4”).getValue()
var invoiceCusName = ss.getRange(“C1”).getValue()
var pdfName = “Invoice ” + invoiceNumber + ” ” + invoiceCusName + ” ” + Utilities.formatDate(new Date(), “GMT+1”, “dd.MM.yyyy”);
var url_ext = ‘exportFormat=pdf&format=pdf’ // export as pdf / csv / xls / xlsx
+ ‘&size=letter’ // paper size legal / letter / A4
+ ‘&portrait=true’ // orientation, false for landscape
+ ‘&fitw=true&source=labnol’ // fit to page width, false for actual size
+ ‘&sheetnames=false&printtitle=false’ // hide optional headers and footers
+ ‘&pagenumbers=false&gridlines=false’ // hide page numbers and gridlines
+ ‘&fzr=false’ // do not repeat row headers (frozen rows) on each page
+ ‘&gid=’; // the sheet’s Id
var response = UrlFetchApp.fetch(url + url_ext + sheet.getSheetId(), {
headers: {
‘Authorization’: ‘Bearer ‘ + token
}
});
var blob = response.getBlob().setName(pdfName + ‘.pdf’);
folder.createFile(blob);
}
Connect with me:
• spencer.farris@gmail.com
• spencerfarris.me
• www.linkedin.com/in/spencer-farris/
• Twitter @FarrisSpencer
• Google Product Expert support.google.com/docs/profile/12305