Automate PDF Transfers from Google Drive to Kindle
I am a voracious reader, and I'm really enjoying reading PDFs on the new Kindle Scribe. What I love most about the Scribe is the natural feel of taking notes on PDF files – it's the best note-taking experience I've ever had! However, uploading PDFs to my Kindle can be a hassle, especially when documents are scattered across different devices. Wouldn't it be great if PDFs from Google Drive automatically appeared on your Kindle? In this tutorial, I'll show you how to achieve exactly that using Apps Script.
What You'll NeedA Google Drive folder where you'll upload your PDFs.
The email address of your Kindle device (something like yourname@kindle.com). You can find this in your Amazon account settings under "Manage Your Content and Devices" → "Preferences" → "Personal Document Settings."
A Google Spreadsheet to keep track of the PDFs you've already sent to your Kindle.
How will the script work?
A Google Drive folder where you'll upload your PDFs.
The email address of your Kindle device (something like yourname@kindle.com). You can find this in your Amazon account settings under "Manage Your Content and Devices" → "Preferences" → "Personal Document Settings."
A Google Spreadsheet to keep track of the PDFs you've already sent to your Kindle.
The script will read all the files in a specific Google Drive every 10 minutes. If it finds PDFs in the folder, it will compare each file against a list of previously sent files stored in a Google Spreadsheet. If new PDFs are found, the script will email them as attachments to your kindle email address. It will then record these sent files in the spreadsheet to prevent resending them in the future.
4 steps to automate sending PDFs from Google Drive to Kindle
Step 1: Prepare Your Google SpreadsheetCreate a new Google Spreadsheet.
Rename it to something like "Sent to Kindle Log."
Note down the Spreadsheet ID from the URL (it's the long string between /d/ and /edit).
https://docs.google.com/spreadsheets/d/<SPREADSHEET_ID>/edit#gid=0
Rename "Sheet 1" to something like "Sent PDFs".
Step 2: Setting Up the Script
Create a new Google Spreadsheet.
Rename it to something like "Sent to Kindle Log."
Note down the Spreadsheet ID from the URL (it's the long string between /d/ and /edit).
https://docs.google.com/spreadsheets/d/<SPREADSHEET_ID>/edit#gid=0
Rename "Sheet 1" to something like "Sent PDFs".
Step 2: Setting Up the Script
First, open Google Drive and go to the folder containing the PDFs you want to send to your Kindle. Then note down the folder's ID from the URL (it's the long string after folders/).
https://drive.google.com/drive/u/0/folders/<FOLDER_ID>
Next, open the Apps Script editor by going to your Google Spreadsheet and clicking on Extensions → Apps Script. Delete any code in the script editor if it's a new project. Then, copy and paste the provided script into the editor. Click the save icon to save your script and give it a name like "Send PDFs to Kindle."
Note
Replace
__FOLDER_ID__
with your Google Drive folder's ID.Replace
__KINDLE_EMAIL__
with your Kindle's email address.Replace
__SENT_FILES_SPREADSHEET_ID__
with your spreadsheet's ID.Replace
__SENT_FILES_SHEET_NAME__
with your chosen sheet name, like "Sent PDFs."
function checkForNewPDFs() {
const FOLDER_ID = "__FOLDER_ID__";
const KINDLE_EMAIL = "__KINDLE_EMAIL__";
const SENT_FILES_SPREADSHEET_ID = "__SENT_FILES_SPREADSHEET_ID__"; // Replace with the ID of your spreadsheet
const SENT_FILES_SHEET_NAME = "__SENT_FILES_SHEET_NAME__";
// Get a reference to the folder containing files to be sent
// to your kindle. Get a list of PDF files in the folder.
const folder = DriveApp.getFolderById(FOLDER_ID);
const filesInFolder = folder.getFilesByType(MimeType.PDF);
// Get a reference to the spreadsheet containing files that were
// already sent and create the sheet if it doesn't exist
const spreadsheet = SpreadsheetApp.openById(SENT_FILES_SPREADSHEET_ID);
spreadsheet.getSheetByName(SENT_FILES_SHEET_NAME) || spreadsheet.insertSheet(SENT_FILES_SHEET_NAME);
const sheet = spreadsheet.getSheetByName(SENT_FILES_SHEET_NAME);
//Get a list of previously sent files from the spreadsheet
const previouslySentFiles = sheet.getDataRange().getValues();
//Iterate through each file in the folder.
//Add files that haven't already been sent to an array.
//Ensure the total size of attachments does not exceed 25MB.
const pdfFilesToSend = [];
let file = null;
let totalAttachmentSize = 0;
while (filesInFolder.hasNext()) {
file = filesInFolder.next();
if (!previouslySentFiles.some(row => row[0] === file.getName())) {
//Do not exceed total attachment size of 25MB
if (file.getSize() + totalAttachmentSize < 25000000) {
pdfFilesToSend.push(file);
totalAttachmentSize += file.getSize();
}
}
}
// Send an email with the new PDFs as attachments
if (pdfFilesToSend.length > 0) {
GmailApp.sendEmail(KINDLE_EMAIL, "New PDFs for Kindle", "", {
attachments: pdfFilesToSend.map(file => file.getAs(MimeType.PDF))
});
// Update the spreadsheet with the files that were sent.
let rowsToAppend = [];
pdfFilesToSend.forEach(file => rowsToAppend.push([file.getName(), file.getId()]));
sheet.appendRows(rowsToAppend);
}
}
Test your script by uploading a few PDFs to your Drive folder and running the script. You may need to authorize the script if you are running it for the first time. When the script runs, it will send an email with the files attached to your @kindle.com email address. You will be able to see this email in the sent folder in Gmail.
Step 3: Set up a trigger
The final step is to automate this possess by setting up a trigger.
Click on the clock icon in the left sidebar to open the "Current project's triggers" page.
Click on "+ Add Trigger" in the lower right corner.
Choose the following options for the new trigger:
Choose which function to run: checkForNewPDFs
Choose which deployment should run: Head
Select event source: Time-driven
Select type of time based trigger: Minutes timer
Select minute interval: Every 10 minutes
Click "Save".
Step 4: Enjoy Automated Delivery
Now, every 10 minutes, your script will check your Google Drive folder for new PDFs. If it finds any, it'll send them to your Kindle and log the details in your spreadsheet. Make sure you've approved the kindle.com email address in your Amazon account to receive documents.
Additional TipsFile Size Limit: The script checks the total size of attachments and ensures it doesn't exceed the 25MB limit. Be mindful of this when adding PDFs to your folder.
Spreadsheet Logs: The log in your Google Spreadsheet helps you track what's been sent. It's handy for troubleshooting and record-keeping.
Manual Runs: You can manually run the checkForNewPDFs function from the Apps Script editor to test or perform an immediate check.
File Size Limit: The script checks the total size of attachments and ensures it doesn't exceed the 25MB limit. Be mindful of this when adding PDFs to your folder.
Spreadsheet Logs: The log in your Google Spreadsheet helps you track what's been sent. It's handy for troubleshooting and record-keeping.
Manual Runs: You can manually run the checkForNewPDFs function from the Apps Script editor to test or perform an immediate check.
With this setup, your latest reads are seamlessly delivered to your Kindle, letting you focus on enjoying your books wherever you are. I hope this tutorial was helpful. Happy reading!
Master Google Sheets Automation
I'd appreciate any feedback you can give me regarding this post.
Was it useful? Are there any errors or was something confusing? Would you like me to write a post about a related topic? Any other feedback is also welcome. Thank you so much!