This mini-guide explains how to connect Google Drive to Google Colab and access your files using Python.

1. Upload Your File to Google Drive

Upload the PDF file you want to use to your Google Drive.

2. Mount Google Drive

Run the following code in your Colab notebook:

from google.colab import drive drive.mount("/content/drive") 

Follow the prompts to authorize access to your Google Drive.

Once mounted, your files will be accessible through the /content/drive directory.

3. Specify the File Path

Define the path to your PDF file:

file_path = "/content/drive/MyDrive/sample.pdf" 

Replace data.pdf with your actual filename.

If the file is in a subfolder, include the subfolder name, for example Projects, in the path:

file_path = "/content/drive/MyDrive//Projects/sample.pdf" 

To check whether the file exists at file_path in the Google Colab environment, run:

import os print(os.path.exists(file_path)) 

Complete Example

from google.colab import drive drive.mount("/content/drive") file_path = "/content/drive/MyDrive/sample.pdf" import os print(os.path.exists(file_path)) 

Open the notebook

Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.

[Open in Google Colab]

This mini-guide was originally published on PDF Python Hub, where you can find more in-depth Python resources for working with PDFs.

What's Next? Install PyMuPDF in Google Colab

Learn how to install PyMuPDF so you can start working with PDF documents in Python.

How to Install PyMuPDF in Google Colab →