# Automated PDF Data Extraction from Gmail and Google Sheets Integration

> Developed an automated solution for a client who received daily PDFs via email.

Section: Google Apps Script

Page: https://mburhan.com/case/gas-automated-pdf-data-extraction-from-gmail

## Project Overview

This solution processes PDF attachments received by email, extracts relevant information, and transfers the data into a designated Google Sheet. It also supports manual PDF uploads and scheduled email fetching.

**Technology:** Gmail, Google Sheets, Python, FastAPI

## 01. The Challenge

Processing daily PDF attachments manually requires downloading files, extracting important information, validating data, and entering it into Google Sheets.

## 02. The Solution

An automated workflow was developed to fetch PDF attachments from Gmail, extract relevant fields, validate the data, and populate Google Sheets. A manual upload interface is also available.

## 03. Key Features

- **User Authentication:** Provides a login mechanism for users.
- **PDF Upload:** Allows users to upload PDF files manually.
- **Data Extraction:** Extracts fields such as order code, shipping address, and product details.
- **Google Sheets Integration:** Transfers extracted data into a designated spreadsheet.
- **Scheduled Email Fetching:** Retrieves PDF attachments from email at scheduled intervals.
- **Data Validation:** Checks data consistency and accuracy.

## 04. How It Works

**Scheduled workflow**

1. Fetch PDF attachments from Gmail.
2. Parse the PDF and extract relevant data.
3. Validate the extracted information.
4. Transfer the data to Google Sheets.

**Manual workflow**

1. User logs in.
2. User uploads a PDF.
3. The backend processes the file and sends the extracted data to Google Sheets.

## 05. Workflow

Image (https://mburhan.com/uploads/5e5729a4f078d5e363952495.png)

**Manual Upload:**

Image (https://mburhan.com/uploads/f21e056b58dcd147327c3c7d.png)

## 06. Implementation

The FastAPI backend handles file uploads, invoice processing, and spreadsheet integration. The `process.py` module processes uploaded files, converts extracted invoice data into a dataframe, and passes it to the Google Sheets client.

Image: The FastAPI backend that handles the upload, invoice parsing, and Sheets integration. (https://mburhan.com/case-content/google-apps-script-portfolio/image2.png)

## 07. Outcome

The solution reduces manual PDF processing and data-entry work by combining scheduled email fetching, manual uploads, data extraction, validation, and Google Sheets integration.
