Organize PDF Output by Date in Google Drive
Date-based folder structures make it easy to find a PDF from a specific day or month without remembering the exact filename. Set this up once and every conversion lands in the right dated folder automatically.
Building the folder path
Use a two-level structure: a year folder containing month folders. Check whether the year folder exists using parentFolder.getFoldersByName(year). If it does not exist, create it. Then do the same for the month folder inside the year folder.
Creating folders on demand
A helper function that takes a parent folder and a name, checks for an existing folder with that name, and either returns it or creates it is the cleanest way to handle this. Call it for the year, then again for the month, and you always have the right target folder regardless of whether it has been created before.
Naming the PDFs within the folder
Inside a dated folder, the filename can be simpler since the date context comes from the folder. Use just the document name plus .pdf, or add a timestamp for intra-day granularity. Consistency matters more than complexity: pick a pattern and apply it everywhere.
Frequently Asked Questions
Can I organize by week number instead of month?
Yes. Use Utilities.formatDate(new Date(), tz, 'yyyy-ww') to get the year and ISO week number as a string. Use this as the subfolder name.
Related article
Use Docs to PDF with Google Drive →Ready to Try It?
Install the free Chrome extension and start converting your Google Docs to PDF in one click.
Install Free Extension