As the title suggest, I want to be able to download the pdf file this code creates with the title I took from a cell value of its sheet. Thanks in advance!
function printSelectedRange() {
SpreadsheetApp.flush();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formS = ss.getActiveSheet();
var range = formS.setActiveRange(formS.getRange("B7:J58"));
var gid = formS.getSheetId();
var printRange = objectToQueryString({
'c1': range.getColumn() - 1 ,
'r1': range.getRow() - 1,
'c2': range.getColumn() + range.getWidth() -1 ,
'r2': range.getRow() + range.getHeight()
});
var url = ss.getUrl().replace(/edit$/, '') + 'export?format=pdf' + PDF_OPTS + printRange + "&gid=" + gid;
var htmlTemplate = HtmlService.createTemplateFromFile('js');
htmlTemplate.url = url;
SpreadsheetApp.getUi().showModalDialog(htmlTemplate.evaluate().setHeight(10).setWidth(400),'Purchase Request by ');
}
function objectToQueryString(obj) {
return Object.keys(obj).map(function(key) {
return Utilities.formatString('&%s=%s', key, obj[key]);
}).join('');
}
<html>
<head>
<base target="_top">
</head>
<body>
<script>
window.open('<?=url?>','_blank','width=800, height=600');
google.script.host.close();
</script>
</body>
</html>