pdf which was created in google-apps-script need to set a password then this pdf will be attached with email service
Is there any parameter to set a password within an export "url" before it is exported to Google drive?
function createPDF(ssId, sheet, pdfName) {
const fr = 0, fc = 0, lc = 9, lr = 27;
const url = "https://docs.google.com/spreadsheets/d/" + ssId + "/export" +
"?format=pdf&" +
"size=8&" +
"fzr=true&" +
"portrait=false&" +
"fitw=true&" +
"gridlines=false&" +
"printtitle=false&" +
"top_margin=0.25&" +
"bottom_margin=0.25&" +
"left_margin=0.25&" +
"right_margin=0.25&" +
"sheetnames=false&" +
"pagenum=UNDEFINED&" +
"attachment=true&" +
"gid=" + sheet.getSheetId() + '&' +
"r1=" + fr + "&c1=" + fc + "&r2=" + lr + "&c2=" + lc;
const params = { method: "GET", headers: { "authorization": "Bearer " + ScriptApp.getOAuthToken() } };
const blob = UrlFetchApp.fetch(url, params).getBlob().setName(pdfName + '.pdf');
// Gets the folder in Drive where the PDFs are stored.
const folder = getFolderByName_(OUTPUT_FOLDER_NAME);
const pdfFile = folder.createFile(blob);
return pdfFile;
}
No.
Unfortunately, there is no way of setting a password of an exported Drive File, that is, by using the Files.export method. That is for pdf files as well as other MIME types.
So, the password protection would have to be added (either manually or programatically) after the export from Drive.
Related
I created a new spreadsheet with a single sheet holding the subset of data of interest. My script is in the original spreadsheet. In that code I am attempting to create a PDF of the new spreadsheet. The URL that my code generates is:
exportUrl=https://docs.google.com/spreadsheets/d/1M82johI78eIrEf8u9RV_5kPgCDAaSfOcoGVYAyno5gE/?usp=drivesdk/export?exportFormat=pdf&format=pdf&size=LETTER&portrait=true&fitw=true&top_margin=0.75&bottom_margin=0.75&left_margin=0.7&right_margin=0.7&sheetnames=false&printtitle=false&pagenum=false&gridlines=true&fzr=FALSE
The PDF generated in MyDrive does not have the icon of a PDF. If I preview it I see:
<!DOCTYPE html><html lang="en"><head><script nonce="siOEWKm8X/lqnbWRNS06ow">var DOCS_timing={}; DOCS_timing['pls']=new Date().getTime();</script><meta property="og:title" content="tempSs"><meta property="og:type" content="article"><meta property="og:site_name" content="Google Docs"><meta property="og:url" content="https://docs.google.com/spreadsheets/d/1M82johI78eIrEf8u9RV_5kPgCDAaSfOcoGVYAyno5gE/edit?usp=drivesdk/export?exportFormat%3Dpdf&format=pdf&size=LETTER&portrait=true&fitw=true&top_margin=0.75&bottom_margin=0.75&left_margin=0.7&right_margin=0.7&sheetnames=false&printtitle=false&pagenum=false&gridlines=true&fzr=FALSE&usp=embed_facebook"><meta property="og:description" content="Sheet1
Abdalla,WilliamAbdalla
Aden,VickieAden
Allen,VeronicaAllen
etc.
When I download it and it has a file extension of html. If I open it the data is there but there is a lot of header stuff which makes no sense. If I change the file extension to pdf I get Error: Failed to load pdf
My code:
/**
* based on https://xfanatical.com/blog/print-google-sheet-as-pdf-using-apps-script/
*/
function exportAsPDF() {
fileName = “tempSs”;
var ssId = getMostRecentFile(fileName);
var ssBaseUrl = getMostRecentFile(fileName);
var blob = _getAsBlob(ssBaseUrl);
_exportBlob(blob, fileName);
}
/**
* Assume multiple spreadsheets with same name
* only want to use the most recent
*/
function getMostRecentFile(fileName) {
ssIt = DriveApp.getFilesByName(fileName);
var createDate, prevCreateDate, tempSsId;
var result = [];
while (ssIt.hasNext()) {
var file = ssIt.next();
result.push([file.getDateCreated(),file.getId(), file.getUrl()]);
}
var dTime = result.sort()[0][0];
var tempSsId = result.sort()[0][1];
var ssBaseUrl = result.sort()[0][2];
// Logger.log(“tempSsId: ” + tempSsId + ” dTime: ” + dTime);
return ssBaseUrl;
}
function _getAsBlob(ssUrlBase) {
// Logger.log(“ssUrlBase before remove edit: ” + ssUrlBase );
var ssUrlBase = ssUrlBase.replace(/edit?/,”);
Logger.log(“ssUrlBase: ” + ssUrlBase );
var exportUrl = ssUrlBase
+ ‘/export?exportFormat=pdf&format=pdf’
+ ‘&size=LETTER’
+ ‘&portrait=true’
+ ‘&fitw=true’
+ ‘&top_margin=0.75’
+ ‘&bottom_margin=0.75’
+ ‘&left_margin=0.7’
+ ‘&right_margin=0.7’
+ ‘&sheetnames=false&printtitle=false’
+ ‘&pagenum=false’
+ ‘&gridlines=true’
+ ‘&fzr=FALSE’;
Logger.log(‘exportUrl=’ + exportUrl);
var response = UrlFetchApp.fetch(exportUrl, {
headers: {
Authorization: ‘Bearer ‘ + ScriptApp.getOAuthToken(),
},
})
return response.getBlob();
}
Why am I not getting a valid PDF in MyDrive or when downloaded? My thanks to everyone. I would not have got this far without constant use of the fine answers on stackoverflow.
Modification points:
When I saw the URL of exportUrl=https://docs.google.com/spreadsheets/d/1M82johI78eIrEf8u9RV_5kPgCDAaSfOcoGVYAyno5gE/?usp=drivesdk/export?exportFormat=pdf&format=pdf&size=LETTER&portrait=true&fitw=true&top_margin=0.75&bottom_margin=0.75&left_margin=0.7&right_margin=0.7&sheetnames=false&printtitle=false&pagenum=false&gridlines=true&fzr=FALSE. I notice that the modification point.
I think that /?usp=drivesdk/export? is the modification point. Please modify to /export?. I think that this is the reason of your issue.
And, in your script, the fonts of the double quotations and the single quotations are required to be modified. In your script, please modify “ and ” to ", and ‘ and ’ to '.
When above points are reflected to your script, it becomes as follows.
Modified script:
function exportAsPDF() {
fileName = "tempSs";
// var ssId = getMostRecentFile(fileName); // It seems that this variable is not used in your script.
var ssBaseUrl = getMostRecentFile(fileName);
var blob = _getAsBlob(ssBaseUrl);
_exportBlob(blob, fileName);
}
function getMostRecentFile(fileName) {
ssIt = DriveApp.getFilesByName(fileName);
var createDate, prevCreateDate, tempSsId;
var result = [];
while (ssIt.hasNext()) {
var file = ssIt.next();
result.push([file.getDateCreated(),file.getId(), file.getUrl()]);
}
var dTime = result.sort()[0][0];
var tempSsId = result.sort()[0][1];
var ssBaseUrl = result.sort()[0][2];
return ssBaseUrl;
}
function _getAsBlob(ssUrlBase) {
var ssUrlBase = ssUrlBase.replace(/\/edit.+/,""); // Modified
var exportUrl = ssUrlBase
+ '/export?exportFormat=pdf&format=pdf'
+ '&size=LETTER'
+ '&portrait=true'
+ '&fitw=true'
+ '&top_margin=0.75'
+ '&bottom_margin=0.75'
+ '&left_margin=0.7'
+ '&right_margin=0.7'
+ '&sheetnames=false&printtitle=false'
+ '&pagenum=false'
+ '&gridlines=true'
+ '&fzr=FALSE';
var response = UrlFetchApp.fetch(exportUrl, {headers: {Authorization: 'Bearer ' + ScriptApp.getOAuthToken()}});
return response.getBlob();
}
Note:
From your question, I couldn't understand about _exportBlob(blob, fileName);. So it supposes that _exportBlob(blob, fileName); works.
Currently my script saves the PDF with the name export.pdf and then renames it to the value I have in one of the cells of my spreadsheet, the problem with that is that my website's API ends up taking the file when it is created and all are collected like export.pdf instead of the name I really need.
Is there an option to create the PDF with the correct name instead of renaming it?
//Create PDF
SpreadsheetApp.flush();
var theurl = 'https://docs.google.com/a/mydomain.org/spreadsheets/d/' +
'IDSPREADSHEETIDSPREADSHEETIDSPREADSHEET' +
'/export?format=pdf' +
'&size=0' +
'&portrait=true' +
'&fitw=true' +
'&top_margin=0' +
'&bottom_margin=0' +
'&left_margin=0' +
'&right_margin=0' +
'&sheetnames=false&printtitle=false' +
'&pagenum=false' +
'&gridlines=false' +
'&fzr=FALSE' +
'&gid=' +
'IDPAGEIDPAGEIDPAGEIDPAGE';
var token = ScriptApp.getOAuthToken();
var docurl = UrlFetchApp.fetch(theurl, { headers: { 'Authorization': 'Bearer ' + token } });
var pdfBlob = docurl.getBlob();
//...get token and Blob (do not create the file);
var fileName = ss.getSheetByName("Gerais").getRange("H2").getValue();
//Access or create the 'Squads' folder;
var folder;
var folders = DriveApp.getFoldersByName("Squads");
if(folders.hasNext()) {
folder = folders.next();
}else {
folder = DriveApp.createFolder("Squads");
}
//Remove duplicate file with the same name;
var existing = folder.getFilesByName(fileName);
if(existing.hasNext()) {
var duplicate = existing.next();
if (duplicate.getOwner().getEmail() == Session.getActiveUser().getEmail()) {
var durl = 'https://www.googleapis.com/drive/v3/files/'+duplicate.getId();
var dres = UrlFetchApp.fetch(durl,{
method: 'delete',
muteHttpExceptions: true,
headers: {'Authorization': 'Bearer '+token}
});
var status = dres.getResponseCode();
if (status >=400) {
} else if (status == 204) {
folder.createFile(pdfBlob).setName(fileName);
}
}
} else {
folder.createFile(pdfBlob).setName(fileName);
Issue:
Setting file name after creating file
folder.createFile(pdfBlob).setName(fileName);
Solution:
Set the blob name before creating file:
folder.createFile(pdfBlob.setName(fileName));
I have a Google Sheet Script that sends the page to an email as a PDF which has been working perfectly until yesterday. Suddenly it started sending corrupted PDF's that can not be opened.
The Script runs just fine, if just can not open up the PDF file as it says "Can Not Display - Invalid format".
Any ideas on why it may have stopped working?
function sendSheetToPdfwithA1MailAdress(){ // this is the function to call
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheets()[0]; // it will send sheet 0 which is the first sheet in the spreadsheet.
// if you change the number, change it also in the parameters below
var shName = sh.getName()
// This function uses a cell in the spreadsheet that names the file that is being saved as getfilename(). using this function will pull from a certain Cell (G4 in this case)
function getFilename() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('N1944E'); // Edit the sheet name as necessary
var cell = sheet.getRange('C8'); //Cell to pull file name from.
var filename = cell.getValue();
return filename;
}
sendSpreadsheetToPdf(0, shName, sh.getRange('C6').getValue(),"Air Attack Daily Fire Sheet " + getFilename() );
}
function sendSpreadsheetToPdf(sheetNumber, pdfName, email,subject, htmlbody) {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var spreadsheetId = spreadsheet.getId()
var sheetId = sheetNumber ? spreadsheet.getSheets()[sheetNumber].getSheetId() : null;
var url_base = spreadsheet.getUrl().replace(/edit$/,'');
var url_ext = 'export?exportFormat=pdf&format=pdf' //export as pdf
+ (sheetId ? ('&gid=' + sheetId) : ('&id=' + spreadsheetId))
// following parameters are optional...
+ '&size=A4' // paper size
+ '&portrait=true' // orientation, false for landscape
+ '&fitw=true' // fit to width, false for actual size
+ '&sheetnames=true&printtitle=false&pagenumbers=true' //hide optional headers and footers
+ '&gridlines=false' // hide gridlines
+ '&fzr=false'; // do not repeat row headers (frozen rows) on each page
var options = {
headers: {
'Authorization': 'Bearer ' + ScriptApp.getOAuthToken(),
}
}
var response = UrlFetchApp.fetch(url_base + url_ext, options);
var blob = response.getBlob().setName(pdfName + '.pdf');
if (email) {
var mailOptions = {
attachments:blob, htmlBody:htmlbody
}
MailApp.sendEmail(
email,
subject+" (" + pdfName +")",
"html content only",
mailOptions);
MailApp.sendEmail(
Session.getActiveUser().getEmail(),
" "+subject+" (" + pdfName +")",
"html content only",
mailOptions);
}
}
I had the exact same issue, but I just figured it out. The problem is here:
var url_base = ss.getUrl().replace(/edit$/,'') + "export?";
getUrl() appears to be returning a different version of the url than it was before. It now appends the following on the url: "ouid=###########&urlBuilderDomain=YOURDOMAIN" check it out yourself by using the logger.
That is causing an issue with the pdf export. So I built my own url address by replacing that line with the following:
var url_base = "https://docs.google.com/spreadsheets/d/" + ss.getId() + "/" + "export?";
It now seems to be working! Here's the full code that generates my blob:
function generatePDF(pdfName, sheet, portrait){
var token = ScriptApp.getOAuthToken();
var params = {
headers: {
'Authorization': 'Bearer ' + token,
},
'muteHttpExceptions' : true
};
var sheetId = sheet.getSheetId();
var ss = sheet.getParent();
// var url_base = ss.getUrl().replace(/edit$/,'') + "export?";
var url_base = "https://docs.google.com/spreadsheets/d/" + ss.getId() + "/" + "export?";
var url_ext = 'exportFormat=pdf' //export as pdf
+ '&format=pdf' //export as pdf
+ '&gid=' + sheetId
+ '&size=letter' // paper size
+ '&portrait=' + portrait // orientation, false for landscape
+ '&fitw=true' // fit to width, false for actual size
+ '&sheetnames=false' //optional headers and footers
+ '&printtitle=false' //optional headers and footers
+ '&pagenumbers=true' //page numbers
+ '&gridlines=true' // gridlines
+ '&fzr=true' // repeat row headers (frozen rows) on each page
var response = UrlFetchApp.fetch(url_base + url_ext, params);
var blob = response.getBlob().setName(pdfName + ".pdf");
return blob;
}
Try this:
function sendSpreadsheetToPdf(sheetNumber, pdfName, email,subject, htmlbody) {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var spreadsheetId = spreadsheet.getId()
var sheetId = sheetNumber ? spreadsheet.getSheets()[sheetNumber].getSheetId() : null;
var url_base = "docs.google.com/spreadsheets/d" + spreadsheetId + "/export?";
var url_ext = 'exportFormat=pdf&format=pdf' //export as pdf
+ (sheetId ? ('&gid=' + sheetId) : ('&id=' + spreadsheetId))
// following parameters are optional...
+ '&size=A4' // paper size
+ '&portrait=true' // orientation, false for landscape
+ '&fitw=true' // fit to width, false for actual size
+ '&sheetnames=true&printtitle=false&pagenumbers=true' //hide optional headers and footers
+ '&gridlines=false' // hide gridlines
+ '&fzr=false'; // do not repeat row headers (frozen rows) on each page
var options = {
headers: {
'Authorization': 'Bearer ' + ScriptApp.getOAuthToken(),
},
'muteHttpExceptions' : true
}
var response = UrlFetchApp.fetch(url_base + url_ext, options);
var blob = response.getBlob().setName(pdfName + '.pdf');
if (email) {
var mailOptions = {
attachments:blob, htmlBody:htmlbody
}
MailApp.sendEmail(
email,
subject+" (" + pdfName +")",
"html content only",
mailOptions);
MailApp.sendEmail(
Session.getActiveUser().getEmail(),
" "+subject+" (" + pdfName +")",
"html content only",
mailOptions);
}
}
Can you try this instead of your current blob declaration :
var blob = response.getBlob().getAs('application/pdf').setName(pdfName + ' .pdf');
References:
Class Blob
Need some help, am somewhat confused!
I have written a google apps script for a spreadsheet, accessed from a custom menu, that should create a pdf of the spreadsheet page, and save it in my google drive. The code executes OK and a pdf is created, but all I get is a pdf of a google sign in page (for sheets). I am the owner of the spreadsheet and the drive folder and working in my Google Apps for Education account. If I try the full url (theurl) in a browser, I get the pdf I am after, so that works OK, so must be something to do with the blob or authorisation, but I can't see why? I must be missing something obvious. I have tried some of the authorisation code blocks I have seen but these just freeze the script. Any help much appreaciated. Tim
See attached for pdf output Order
Here is my code:
function spreadsheetToPDF(){
var key = '14vZzkfMj9XSk4pgbQc78s1pBmsakHABJk7_MSX6j7xs'; //docid
var index = 0; //sheet gid / number
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ActiveSheet = ss.getSheetByName('Order Form');
var timestamp = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'-'HHmm");
var supp_name = ActiveSheet.getRange("C12").getValue(); //supplier
var plainonum = ActiveSheet.getRange("C5").getValue(); //order number
var onum = ('0000' + plainonum ).slice(-4); //sets leading zeros to order number
var description = ActiveSheet.getRange("C18").getValue(); //description
var name = 'Order-' + onum +'-' + supp_name + '-' + description + '-' + timestamp + '.pdf'; //makes pdf filename
SpreadsheetApp.flush(); //ensures everything on spreadsheet is "done"
//make the pdf from the sheet
var theurl = 'https://docs.google.com/a/mydomain.org/spreadsheets/d/'
+ key
+ '/export?exportFormat=pdf&format=pdf'
+ '&size=A4'
+ '&portrait=true'
+ '&fitw=true' // fit to width, false for actual size
+ '&sheetnames=false&printtitle=false&pagenumbers=false'
+ '&gridlines=false'
+ '&fzr=false' // do not repeat frozen rows on each page
+ '&gid='
+ index; //the sheet's Id
var docurl = UrlFetchApp.fetch(theurl);
var pdf = docurl.getBlob().setName(name).getAs('application/pdf');
//save the pdf to the folder on drive
try {
folder = DocsList.getFolder('Orders');
}
catch (e) {
folder = DocsList.createFolder('Orders');
}
folder.createFile(pdf);
}
Instead of using UrlFetchApp.fetch(), you can get a reference to the file using the DriveApp class.
Google DriveApp Class
The problem with using this method, is that I don't know of a way to do something like fit the PDF to one page, other than formatting the Sheet before it's saved.
Also, the DocsList class is now deprecated.
Maybe try something like this:
function createPDF() {
var fileToUse = 'FileID';
//Logger.log('fileToUse: ' + fileToUse);
var templateFile = DriveApp.getFileById(fileToUse);
var theBlob = templateFile.getBlob().getAs('application/pdf');
var folderID = folderToSaveTo;
var folder = DriveApp.getFolderById(folderID);
var newFile = folder.createFile(theBlob);
//newFile.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW);
};
Thanks both, and to Zig for pointing me in the right direction. After a bit of digging around I found a script on labnol.org - doing something quite different but showing the oAuth authorisation part.
I needed a new variable
var token = ScriptApp.getOAuthToken();
and then to add some more code to the docurl variable
var docurl = UrlFetchApp.fetch(theurl, { headers: { 'Authorization': 'Bearer ' + token } });
This provided the required authorisation for when the spreadsheet is not public.
Working function:
function spreadsheetToPDF(){
var key = '14vZzkfMj9XSk4pgbQc78s1pBmsakHABJk7_MSX6j7xs'; //docid
var index = 0; //sheet gid / number
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ActiveSheet = ss.getSheetByName('Order Form');
var timestamp = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'-'HHmm");
var supp_name = ActiveSheet.getRange("C12").getValue(); //supplier
var plainonum = ActiveSheet.getRange("C5").getValue(); //order number
var onum = ('0000' + plainonum ).slice(-4); //sets leading zeros to order number
var description = ActiveSheet.getRange("C18").getValue(); //description
var name = 'Order-' + onum +'-' + supp_name + '-' + description + '-' + timestamp + '.pdf'; //makes pdf filename
SpreadsheetApp.flush(); //ensures everything on spreadsheet is "done"
//make the pdf from the sheet
var theurl = 'https://docs.google.com/a/mydomain.org/spreadsheets/d/'
+ key
+ '/export?exportFormat=pdf&format=pdf'
+ '&size=A4'
+ '&portrait=true'
+ '&fitw=true' // fit to width, false for actual size
+ '&sheetnames=false&printtitle=false&pagenumbers=false'
+ '&gridlines=false'
+ '&fzr=false' // do not repeat frozen rows on each page
+ '&gid='
+ index; //the sheet's Id
var token = ScriptApp.getOAuthToken();
var docurl = UrlFetchApp.fetch(theurl, { headers: { 'Authorization': 'Bearer ' + token } });
var pdf = docurl.getBlob().setName(name).getAs('application/pdf');
//save the file to folder on Drive
var fid = '0B1quMlsbdFZyfkZRaWFQZVZLdFNDcC1hZGVqM25NNDhZblhVZktjamJLTVBXRXk5aThtcXc';
var folder = DriveApp.getFolderById(fid);
folder.createFile(pdf);
}
Must go and do some reading up about this!
What you see is by design. You are attempting to bypass user validation. If you look at the docs you will find getAs. https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#getAs(String)
I'm trying to work out how to create a PDF document through Google Apps Script which is displayed in landscape orientation (A4 size). This is the code I'm using to create the PDF so far, which comes out in portrait orientation.
function pdfSheet() {
var d = new Date();
var cdate = d.getDate();
var cmonth = d.getMonth() + 1;
var cyear = d.getFullYear();
var current = [cdate + "-" + cmonth + "-" + cyear];
var imageBlob = UrlFetchApp.fetch("https://sites.google.com/site/mysite/smalllogo.png").getBlob();
var base64EncodedBytes = Utilities.base64Encode(imageBlob.getBytes());
var logo = "<img src='data:image/png;base64," + base64EncodedBytes + "' width='170'/>";
var html = "<table width='100%'><tr><td align='right'>" + logo + "<br><br><b>Date:</b> " + current + "</td></tr></table>"; //PDF content will carry on here.
var gmailLabels = "PDF";
var driveFolder = "My Gmail";
var folders = DriveApp.getFoldersByName(driveFolder);
var folder = folders.hasNext() ?
folders.next() : DriveApp.createFolder(driveFolder);
var subject = 'Test PDF';
var tempFile = DriveApp.createFile("temp.html", html, "text/html");
var page = folder.createFile(tempFile.getAs("application/pdf")).setName(subject + ".pdf")
tempFile.setTrashed(true);
var link = page.getUrl();
Logger.log(link);
}
I took most of this from another user and edited to have the current days date (in EST) in the email subject and the PDF name. Hope it helps!
// Simple function to send Daily Status Sheets
// Load a menu item called "Project Admin" with a submenu item called "Send Status"
// Running this, sends the currently open sheet, as a PDF attachment
function onOpen() {
var submenu = [{name:"Send Status", functionName:"exportSomeSheets"}];
SpreadsheetApp.getActiveSpreadsheet().addMenu('Project Admin', submenu);
}
function creatPDF() {
SpreadsheetApp.flush();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//Date set with format in EST (NYC) used in subject and PDF name
var period = Utilities.formatDate(new Date(), "GMT+5", "yyyy.MM.dd");
var url = ss.getUrl();
//remove the trailing 'edit' from the url
url = url.replace(/edit$/, '');
//additional parameters for exporting the sheet as a pdf
var url_ext = 'export?exportFormat=pdf&format=pdf' + //export as pdf
//below parameters are optional...
'&size=letter' + //paper size
'&portrait=false' + //orientation, false for landscape
'&fitw=true' + //fit to width, false for actual size
'&sheetnames=false&printtitle=false&pagenumbers=false' + //hide optional headers and footers
'&gridlines=false' + //hide gridlines
'&fzr=false' + //do not repeat row headers (frozen rows) on each page
'&gid=' + sheet.getSheetId(); //the sheet's Id
var token = ScriptApp.getOAuthToken();
var response = UrlFetchApp.fetch(url + url_ext, {
headers: {
'Authorization': 'Bearer ' + token
}
});
var blob = response.getBlob().setName(ss.getName() + " " + period + '.pdf');
//from here you should be able to use and manipulate the blob to send and email or create a file per usual.
var email = 'email#co-email.com';
var subject = "subject line " + period ;
var body = "Please find attached your Daily Report.";
//Place receipient email between the marks
MailApp.sendEmail( email, subject, body, {attachments:[blob]});
}