I have the basic script working fine. It does exactly what I want it to do. It takes the Google Sheet, turns it into a PDF, and emails me the PDF.
My question is, how can I adjust the margins on the PDF? I need to set the PDF to fit the page. I can't just resize the sheet because it throws the spacing off.
/* Email Google Spreadsheet as PDF */
function PDF() {
// Send the PDF of the spreadsheet to this email address
var email = "gmail.com";
// Get the currently active spreadsheet URL (link)
var ss = SpreadsheetApp.openByUrl(
'https://docs.google.com');
// Subject of email message
var subject = "PAR - " + ss.getRange("A6:A6").getValue() +" - "+ ss.getRange("A5:A5").getValue();
// Email Body can be HTML too
var body = "Name - " + ss.getRange("A6:A6").getValue() +" - "+ ss.getRange("A5:A5").getValue();
var blob = DriveApp.getFileById(ss.getId()).getAs("application/pdf");
blob.setName("Name - " + ss.getRange("A6:A6").getValue() +" - "+ ss.getRange("A5:A5").getValue() + ".pdf");
// If allowed to send emails, send the email with the PDF attachment
if (MailApp.getRemainingDailyQuota() > 0)
GmailApp.sendEmail(email, subject, body, {
htmlBody: body,
attachments:[blob]
});
}
I've seen a script like this but can't figure out how to get it to work on my script.
var url_ext = 'exportFormat=pdf&format=pdf' // export as pdf / csv / xls / xlsx
+ '&size=letter' // paper size legal / letter / A4
+ '&portrait=false' // 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