Convert an Entire Google Drive Folder to PDF with Apps Script
Processing a whole folder of Google Docs is a matter of iterating over the files and calling the export function for each one. Apps Script makes this straightforward with DriveApp's folder and file iterators.
Getting all files in a folder
Use DriveApp.getFolderById(folderId).getFiles() to get an iterator over all files in the folder. Loop through it with a while loop using iterator.hasNext() and iterator.next(). Check each file's MIME type against MimeType.GOOGLE_DOCS to filter for Docs only.
Processing each file
For each Google Doc in the iterator, call your PDF export function with the file ID. Save the resulting PDF to your target folder. Log the filename and any errors so you have a record of what ran.
Handling nested folders
If the folder contains subfolders, use folder.getFolders() to get a folder iterator and recurse into each subfolder. A recursive helper function that accepts a folder as its argument keeps the logic clean and handles any folder depth.
Frequently Asked Questions
Can I filter which files get converted inside the folder?
Yes. Check the file's MIME type, name, last modified date, or any other property before converting. For example, only convert files modified in the last 24 hours by comparing file.getLastUpdated() to the current date.
How long does it take to convert a large folder?
Each conversion takes a few seconds. A folder of 50 documents processes in a few minutes. Apps Script has a 6-minute execution limit per run, so very large folders need to be split across multiple triggered runs.
Ready to Try It?
Install the free Chrome extension and start converting your Google Docs to PDF in one click.
Install Free Extension