Overwrite vs. New File When Saving PDFs to Drive

When an automated conversion runs repeatedly on the same document, you need to decide whether each run replaces the previous PDF or creates a new one alongside it. Both patterns have valid use cases.

When to overwrite

Overwriting makes sense when you only need the latest version and do not need a history. A team status document that gets updated weekly and distributed as a PDF is a good example. There is no value in keeping last week's version once this week's is ready.

Implementing overwrite in Apps Script

Search for an existing file with the target name using folder.getFilesByName(filename). If the iterator has a result, call file.setTrashed(true) on the old file before creating the new one. This moves the old file to Trash, not permanent deletion. You can restore it from Trash if needed.

When to create new files

Creating a new file each run is better for audit trails, approval records, and any situation where you need to show what the document looked like at a specific time. Use timestamped filenames or versioned filenames like docName_v1, docName_v2 to distinguish each export.

Frequently Asked Questions

Does trashing the old file also delete it permanently?

No. setTrashed(true) moves the file to Trash. It stays there for 30 days before permanent deletion. You can restore it from Trash during that period.

Ready to Try It?

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

Install Free Extension