So, I have the codes shown below, and it works fine!. The pdf file in question is named 'targetfile.pdf, which already exists.
Question is:
How do I take the pdf file and move/copy it to the browser download file in the local computer. I just need the codes for that. The idea is that the code will run and the pdf file is automatically sent to the 'download' folder in the PC.
I have tried several coding but to no avail. This is my request for help after I exhausted all other actions. Please help. Any assistance is greatly appreciated. Thank you in advance.
function starthere(){
var doc = SpreadsheetApp.getActiveSpreadsheet();
var key = doc.getId();
var folder = DriveApp.getFolderById(key); // testFormSheet
var folderid = folder.getParents().next().getId(); // id of folder
var folder = DriveApp.getFolderById(folderid); // testFormSheet
Logger.log(folder);
Logger.log(folderid);
Logger.log(folder);
Logger.log(doc.getName()); //testdownload
// for this test, the target file to download is 'targetfile.pdf'.
// we must find a way to download the file.
var dfile = folder.getFilesByName("targetfile.pdf");
while(dfile.hasNext()){
var currfile = dfile.next();
};
Logger.log(currfile.getName()); // targetfile.pdf
Logger.log(currfile.getId()); // file id of targetfile.pdf