Google Docs PDF Export Adds Extra Blank Pages at the End

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":, > 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); > 
asked Jan 7, 2022 at 17:47 39 2 2 silver badges 7 7 bronze badges How do you export the sheets, via script or file -> download -> pdf -> export option? Commented Jan 7, 2022 at 18:35

Via script, but I notice the same problem when printing the sheet, blank pages are beeing generated at the end. I remember having this same problem about 5 years ago, but it was fixed, now is back.