I'm trying to export part of a sheet (called "Certificado") to PDF. Just the range A1:H46. However, it exports all the sheet up to this cell in one page of the PDF and the rest of the sheet follows on a second page. So I would like to either get rid of that second page or just export the range A1:H46. This last option is what I'm trying to do in the following code creating and deleting a new sheet, but with no success. Just in case it is important, my sheet to export includes an image.
I've read in other questions to hide rows that I don't want in the exported PDF, but I cannot hide those rows as I need them in the sheet to input other info that links to other sheet.
Here is the Sheet input. Here is the PDF I'm getting. The output I want would be just the first page of this PDF, which is up to the row H46 in the sheet. Thanks a lot!
var originalSpreadsheet = SpreadsheetApp.getActive();
var sourcesheet = originalSpreadsheet.getSheetByName("Certificado");
var sourcerange = sourcesheet.getRange('A1:H46');
var sourcevalues = sourcerange.getValues();
var newSpreadsheet = SpreadsheetApp.create("Spreadsheet to export"); //cualquier nombre
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var sheet = sourcesheet.copyTo(newSpreadsheet);
var destrange = sheet.getRange('A1:H46');
destrange.setValues(sourcevalues);
newSpreadsheet.getSheetByName('Hoja 1').activate();
newSpreadsheet.deleteActiveSheet();
var pdf = DriveApp.getFileById(newSpreadsheet.getId());
var theBlob = pdf.getBlob().getAs('application/pdf').setName(sourcesheet.getRange('C34').getValue());
var folder = DriveApp.getFolderById('10JsCe-lNb2_8RIUu34IKCaz_wBGIAja3');
var newFile = folder.createFile(theBlob);
DriveApp.getFileById(newSpreadsheet.getId()).setTrashed(true);
Thank you @Tanaike for you help. Here is one possible answer to my question for anyone interested in it.