One solution will be, create a folder inside of Drive, convert the documents to PDFs, and download the folder as a .zip
.
function convertDocuments() {
/* Select the Spreadsheet */
const SS_ID = "SPREADSHEET_ID"
const SS = SpreadsheetApp.openById(SS_ID)
const PDF_MIME = "application/pdf"
const newFolder = DriveApp.createFolder('PDFs')
/* Get the links */
const getLinks = SS.getRange('A2:A').getValues()
getLinks.forEach((cells)=>{
const link = cells[0]
if(link==="") return
/* Getting the ID from the URL */
const parseID = link.toString().split("/")[5]
/* CREATE THE PDF */
const document = DriveApp.getFileById(parseID).getAs(PDF_MIME).copyBlob()
/* Inserting the PDF into the file */
newFolder.createFile(document)
})
Logger.log(newFolder.getUrl())
/* downloadFolder(newFolder.getId()) */
}
The steps are as follows:
- Retrieve all links inside the
A
column
- Use
DriveApp
in order to create a PDF for every link (link needs to be parsed for retrieving the ID)
- Place the PDF inside the Drive Folder
- From here, you have two possibilities:
- Use the UI to download the folder
- Use this function (provided by @Tanaike) to get directly the download link. Inside my script is referenced as
downloadFolder
function downloadFolder(folderId) {
const folder = DriveApp.getFolderById(folderId);
const files = folder.getFiles();
let blobs = [];
while (files.hasNext()) {
blobs.push(files.next().getBlob());
}
const zipBlob = Utilities.zip(blobs, folder.getName() + ".zip");
const fileId = DriveApp.createFile(zipBlob).getId();
const url = "https://drive.google.com/uc?export=download&id=" + fileId;
Logger.log(url);
}
Documentation