Automatically Save Google Docs as PDF Using Apps Script

Using Apps Script to automatically save to PDF gives you full control over which documents get exported, where the PDFs go, how they are named, and when the export runs. It requires a small amount of JavaScript but no special environment or tools.

The basic script

Using Apps Script to automatically save PDFs starts with opening script.google.com and creating a new project. The core function uses DriveApp to get the source folder, iterates over the files, exports each one to PDF by fetching the export URL with UrlFetchApp, and creates the PDF file in the target folder using DriveApp.createFile(). This covers the entire export workflow.

Handling the export URL

The Google Drive export URL for a PDF is in the format: https://docs.google.com/document/d/FILE_ID/export?format=pdf. Replace FILE_ID with the document's Drive file ID. Use UrlFetchApp.fetch() with the OAuth token from ScriptApp.getOAuthToken() to authenticate the request.

Error handling and logging

Wrap the export in a try-catch block. If a file fails to export, log the error with Logger.log() and continue with the rest of the batch. After the loop, use MailApp.sendEmail() to send a summary of successes and failures to your email address.

Frequently Asked Questions

Where do I find the file ID for my Google Doc?

The file ID is in the document URL. For a URL like docs.google.com/document/d/XXXX/edit, the ID is the XXXX part between /d/ and /edit.

Ready to Try It?

Install the free Chrome extension and start converting your Google Docs to PDF in one click.

Install Free Extension