'Margins/Headers are incorrect when using app script to convert sheet to PDF and generating email

Hoping someone might be able to lend a hand. I have an app script that converts an existing sheet to PDF that then emails to a recipient. Works perfectly except that the margins are not conforming to what I have in the script. Oddly enough, I have a similar app script that converts the same sheet to PDF to be downloaded and the margins are correct. I am providing a snippet of the code if it may help.

var printRange = '&c1=0' + '&r1=0' + '&c2=41'  + '&r2=5'; // B2:APn

var url= ss.getUrl().replace(/edit$/, '') + 
"format=pdf&"+
"fmcmd=12&"+
"size=0&"+
"fzr=true&"+
"gid="+322778635+"&"+
"sheetnames=false&"+
"pagenum=UNDEFINED&"+
"gridlines=true&"+
"portrait=true&"+
"scale=2&"+
"fitw=false&"+
"horizontal_alignment=CENTER&"+
"top_margin=0.00&"+
"bottom_margin=0.00&"+
"left_margin=0.00&"+
"right_margin=0.00&"+
"ir=false&"+
"ic=false&"+
"r1=0&"+
"c1=0&"+
"r2=41&"+
"c2=5&"+

"attachment=true&"+ printRange;


var blob = DriveApp.getFileById(ss.getId()).getAs("application/pdf");

blob.setName(ss.getName() + ".pdf");

 var templ = HtmlService
  .createTemplateFromFile('candidate-email');

 templ.candidate = candidate;

 var message = templ.evaluate().getContent();

 MailApp.sendEmail({
 to: candidate.email,
 subject: "New Invoice Submitted from Group!",
 htmlBody: message,
 attachments: [blob],
 });



 
 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source