When exporting the same .indd file in InDesign2021 using the following script, the file size and image quality varies depending on my last manual export.
defaultHQPreset = app.pdfExportPresets.itemByName('[High Quality Print]');
var scriptParentPath = (new File($.fileName)).parent.toString()
var docFile = File(scriptParentPath + "/" + "sample_chapter.indd");
var theDoc = app.open(docFile)
var outputPDFFile = File(docFile.toString()+".pdf");
theDoc.exportFile(ExportFormat.PDF_TYPE, outputPDFFile, false, defaultHQPreset);
theDoc.close(SaveOptions.NO);