I use google spreadsheet to create invoices and send them by email in PDF format, it's been working great, my spreadsheets are yearly base, so every new year I create another one, all my spreadsheet from 2021 are still working fine, but all the new ones I've created for 2022 when I try to print or export PDFs, extra blank pages are beeing added to the end of the document. The number of blank pages are dependent on the number of blank lines on the sheet, but I didn't have this problem before, before even when the sheet has 1000 lines, if the invoice has only 1 page the PDF/Print will only generate 1 page, now if the sheet has 1000 lines it generates 19 blank pages.
Anyone with same problem or a solution?
Link for example: Spreadsheet link
Try to print or download the page and you will see the blank pages generated.
function savePDF() {
const ssh = SpreadsheetApp.getActiveSpreadsheet();
const invoice = ssh.getSheetByName('invoice');
const request = {
"method": "GET",
"headers":{"Authorization": "Bearer
"+ScriptApp.getOAuthToken()},
}
const key = ssh.getId();
const bogus = DriveApp.getRootFolder();
const fetch='https://docs.google.com/spreadsheets/d/'
+ key
+'/export?format=pdf&gid='
+ invoice.getSheetId()
+
'&size=letter&portrait=true
&printtitle=false
&pagenum=CENTER
&sheetnames=false
&gridlines=false
&top_margin=0.25
&bottom_margin=0.50&left_margin=0.25
&right_margin=0.25';
const name = "invoice.pdf";
let pdf = UrlFetchApp.fetch(fetch, request);
pdf = pdf.getBlob().setName(name);
const fold = "Folder ID goes here";
const folder = DriveApp.getFolderById(fold);
const file = folder.createFile(pdf);
}