Automatically Save Google Docs as PDF to a Drive Folder
Automatically saving to a Drive folder keeps PDFs organized and accessible to anyone with folder access. The Apps Script export function saves each PDF to a folder you specify, using the folder's Drive ID.
Getting the target folder ID
Automatically saving to a Drive folder requires the folder ID, not just the folder name. Open the folder in Drive. The URL contains the folder ID after /folders/. Copy that ID and use it in your Apps Script with DriveApp.getFolderById('FOLDER_ID') to get a reference to the folder.
Saving files to the folder
Use folder.createFile(filename, pdfBlob, MimeType.PDF) to save the PDF to the target folder. This creates a new file in that folder each time the script runs. To overwrite instead of creating new files, search for an existing file with the same name using folder.getFilesByName(filename) and remove it before creating the new version.
Using subfolders for organization
For long-running automatic exports, a flat folder fills up quickly. Create subfolders organized by date or project and save each export to the appropriate subfolder. Use folder.createFolder() in the script to create the subfolder if it does not already exist.
Frequently Asked Questions
Can I automatically save PDFs to a shared drive folder?
Yes. Use DriveApp.getSharedDriveById() or navigate from the shared drive root to the target folder. The script user needs Contributor access to the shared drive folder.
Ready to Try It?
Install the free Chrome extension and start converting your Google Docs to PDF in one click.
Install Free Extension