Это то, что я понял для форматирования pdf-файлов google sheet. Просто взломайте код, который вам не нужен. Но это позволит вам установить поля. Я никогда не тратил время на то, чтобы выяснить все варианты .... но это немало. Он печатает только один лист.
function PrintPdfFiles(){
var defSpreadsheet = SpreadsheetApp.getActive()
GoogleSpreadsheetToPdf(defSpreadsheet.getId(), "Sheet3","1 - "+ defSpreadsheet.getName(),0,1,1,0,0,0,
0,1,1,1,'[null,["\\uee15"]]',2,1,'letter',
0,5,0.7,0.5,0.75,0.5,0.5);
GoogleSpreadsheetToPdf(defSpreadsheet.getId(), "Sheet4","2 - "+ defSpreadsheet.getName(),0,1,1,0,0,0,
0,1,1,1,'[null,["\\uee15"]]',2,1,'letter',
0,5,0.7,0.5,0.75,0.5,0.5);
GoogleSpreadsheetToPdf(defSpreadsheet.getId(), "Sheet5","3 - "+ defSpreadsheet.getName(),0,1,0,0,0,0,
0,1,0,1,'null',2,1,'letter',
1,4,1,1.1811023622047245,0.7480314960629921,0.7086614173228347,0.7086614173228347);
}
function GoogleSpreadsheetToPdf(spreadsheetId,sheetName,pdfName,ShowNotes,ShowGridlines,PageNumbers,WorkbookTitle,Sheetname,CurrentDate,
CurrentTime,Repeatfrozenrows,RepeatfrozenCols,PageOrder,PageNmFormat,HorizAlign,VertAlign,PaperSize,
Orientation,Scale,ScaleNumber,topmargin,bottomMargin,leftMargin,RightMargin){
var spreadsheet = SpreadsheetApp.openById(spreadsheetId);
var sheetId = spreadsheet.getSheetByName(sheetName).getSheetId();
var url_base = 'https://docs.google.com/spreadsheets/d/' + spreadsheetId +'/pdf?id=' + spreadsheetId;
var url_ext = '[null,null,null,null,null,null,null,null,null,0,'
+ '[["' + sheetId + '"]]'
+',10000000,null,null,null,null,null,null,null,null,null,null,null,null,null,null,43407.82605613426,null,null,['
+ ShowNotes+',' //(ShowNotes-1isTrue),
+ 'null,'
+ ShowGridlines +',' //(ShowGridlines-0isTrue1isFalse,
+ PageNumbers +',' //(PageNumbers-1isTrue),
+ WorkbookTitle +',' //(WorkbookTitle-1isTrue),
+ Sheetname+',' //(Sheetname-1isTrue),
+ CurrentDate+',' //(CurrentDate-1isTrue),
+ CurrentTime+',' //(CurrentTime-1isTrue),
+ Repeatfrozenrows+',' //(Repeatfrozenrows-1isTrue),
+ RepeatfrozenCols+',' //(RepeatfrozenCols-1isTrue),
+ PageOrder+',' //(PageOrder-1DownthenOver2OverthenDown),
+ '2,null,'
+ PageNmFormat+',' //(Page Number formatting), Page Number formatting "Page 1" - [null,["\\uee15"]]
+ HorizAlign+',' //(HorizAlign-1isLeft2isCenter3isRight),
+ VertAlign+',' //(VertAlign-1isTop2isCenter3isBottom)
+'],["'
+ PaperSize+'",' //letter",
+ Orientation+',' //(1isPortrait-0Landscape),
+ Scale +',' //(Scale-4isFittoPage-5isCustomNumber),
+ ScaleNumber +',' //(Scale),
+'['
+ topmargin+',' //(topmargin),
+ bottomMargin +',' //(bottomMargin),
+ leftMargin+',' //(leftMargin),
+ RightMargin //(RightMargin)
+']],null,0,[["207472796",null,[[21,21]]]]]';
var headers= {
'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()
};
var data = {
"a": "true",
"gf": "[]",
"pc": url_ext
};
var options = {
'headers':headers,
'method' : 'POST',
'payload' : data
};
var response = UrlFetchApp.fetch(url_base, options);
var blob = response.getBlob().setName(pdfName + '.pdf');
var file = DriveApp.createFile(blob);
var fileId = file.getId();
//Check and see if there is a 'PDF files' folder
var PDFFilesFolderId = null;
var RFSFolderId = DriveApp.getFileById(spreadsheetId).getParents().next().getId();
var files = DriveApp.searchFolders('parents="'+RFSFolderId+'" and trashed=false');
while (files.hasNext()) {
var file = files.next();
if(file.getName() == "PDF Files"){
PDFFilesFolderId = file.getId();
}
}
//If the directory is not found create it
if(PDFFilesFolderId == null){
var newFolder=DriveApp.getFolderById(RFSFolderId).createFolder("PDF Files")
files = DriveApp.searchFolders('parents="'+RFSFolderId+'" and trashed=false');
while (files.hasNext()) {
var file = files.next();
if(file.getName() == "PDF Files"){
PDFFilesFolderId = file.getId();
}
}
moveFileId(fileId, PDFFilesFolderId);
}
else{
moveFileId(fileId, PDFFilesFolderId);
}
}
function moveFileId(fileId, toFolderId) {
var file = DriveApp.getFileById(fileId);
var source_folder = DriveApp.getFileById(fileId).getParents().next();
var folder = DriveApp.getFolderById(toFolderId)
folder.addFile(file);
source_folder.removeFile(file);
}