Many organizations rely on Google Drive for collecting documents from clients or field workers. Often, users will upload photographs of documents (like receipts or handwritten forms) taken with their smartphones (as JPEGs or PNGs). Managing these diverse image files is cumbersome. Using Google Apps Script, you can automate this workflow: whenever a new image is added to a specific folder, Google Drive will automatically convert it into a standard PDF document.
Step 1: Prepare the Google Drive Folder
- Open Google Drive and create a new folder where users will upload their images (e.g., “Incoming Receipts”).
- Open the folder. Look at the URL in your browser’s address bar. It will look something like this:
drive.google.com/drive/folders/1A2B3C4D5E6F7G8H9I0J. - Copy the long string of random characters at the end (the Folder ID). You will need this for the script.
Step 2: Create the Apps Script
- Open a new browser tab and navigate to script.google.com.
- Click New Project.
- Delete any default code in the editor and paste the following script:
function convertImagesToPDF() {
// Replace with your Folder ID
var folderId = 'YOUR_FOLDER_ID_HERE';
var folder = DriveApp.getFolderById(folderId);
var files = folder.getFiles();
while (files.hasNext()) {
var file = files.next();
var mimeType = file.getMimeType();
// Check if the file is an image (JPEG or PNG)
if (mimeType === MimeType.JPEG || mimeType === MimeType.PNG) {
// Get the image blob
var imageBlob = file.getBlob();
// Convert the blob to a PDF
var pdfBlob = imageBlob.getAs(MimeType.PDF);
pdfBlob.setName(file.getName().replace(/\.[^/.]+$/, "") + ".pdf");
// Create the new PDF file in the same folder
folder.createFile(pdfBlob);
// Optional: Delete the original image to save space
// file.setTrashed(true);
}
}
}
- Replace
YOUR_FOLDER_ID_HEREwith the ID you copied in Step 1. - Click the Save icon (floppy disk) and name the project “Image to PDF Converter”.
Step 3: Run and Authorize
Before you can automate the script, you must run it manually once to grant it permissions.
- Click the Run button at the top of the editor.
- An “Authorization Required” popup will appear. Click Review Permissions.
- Select your Google account. You may see a warning that the app isn’t verified; click “Advanced” and proceed to the script.
- Click Allow to let the script access your Google Drive.
Step 4: Set up the Automation (Trigger)
Now that the script works, you need to tell Google to run it automatically on a schedule.
- On the left-hand sidebar of the Apps Script editor, click the Triggers icon (it looks like an alarm clock).
- Click the Add Trigger button in the bottom right corner.
- Set the following options:
- Choose which function to run:
convertImagesToPDF - Select event source:
Time-driven - Select type of time based trigger:
Minutes timer - Select minute interval:
Every 15 minutes
- Choose which function to run:
- Click Save.
Google will now silently run your script every 15 minutes in the background. It will scan the target folder, convert any newly uploaded images into PDFs, and leave the standardized PDFs ready for processing.