# Invoice PDF to Spreadsheet (OCR + Gmail automation)

> Turn PDF invoices, digital or scanned, into clean spreadsheet rows. Your agent extracts number, date, parties, amounts and items from any layout, tags each row with your client rules and appends it to Excel or CSV with no duplicates. Optional Gmail to Google Sheets automation.

Invoice PDF to Spreadsheet (OCR + Gmail automation) is a free AI agent skill on Agensi by Francho Lendines, in Workflow Automation. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Francho Lendines](https://www.agensi.io/creators/francho-lendines)
- Category: [Workflow Automation](https://www.agensi.io/skills/workflow-automation)
- Version: 1.0
- Last updated: 2026-11-30
- Security: scan passed (2026-11-30); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/invoice-pdf-to-spreadsheet-ocr-gmail-automation
- Tags: automation, finance, productivity, finance-accounting, python, ocr, excel, google-sheets

## About this skill

Typing invoices into a spreadsheet by hand is slow, and regex-based parsers break the moment a supplier changes their template. This skill lets your agent do it properly: it reads the PDF (running OCR when it's a scan), pulls out every field itself, and appends clean, deduplicated rows to your ledger.

### What it does
- **Reads any PDF invoice.** Digital PDFs use the text layer; scanned ones fall back to local OCR (tesseract). Works with Spanish and English invoices out of the box, and any language tesseract supports.
- **Extracts the fields with the agent, not with regex.** Invoice number, date (ISO), issuer and client with tax IDs (NIF/CIF/VAT), description, subtotal, tax, total and currency. European number formats (`1.234,56`) are normalised.
- **Never invents data.** Missing or unreadable values are left empty and the row is flagged `needs_review`. Rows where subtotal + tax doesn't match the total are flagged too.
- **Classifies by client or supplier.** A small `rules.json` maps names to your own columns: category, account code, cost centre, anything you like.
- **Safe to re-run.** Invoices already in the ledger (same number + issuer) are skipped.
- **Fits your existing sheet.** It keeps your header and column order, can insert rows above a totals row (and stretches the `SUM` formula), and can write the same rows to a second ledger.

### Two modes
1. **Process now:** "Log the invoices in this folder into invoices.xlsx". Your agent runs the bundled scripts and gives you a short summary plus the list of rows to review.
2. **Hands-off Gmail automation:** your agent tailors the bundled Google Apps Script to *your* invoices (writes and tests the extraction patterns against a sample) and walks you through installing it. From then on, invoices that arrive by email are OCR'd and logged in Google Sheets on a timer, with no agent needed.

### What's inside
- `SKILL.md`: the workflow and extraction rules
- `scripts/extract_text.py`: text layer or OCR fallback, JSON output
- `scripts/append_rows.py`: classify, dedupe and append to CSV/XLSX
- `reference/apps-script/`: the Gmail → Sheets script and setup guide
- `reference/rules.example.json`

### Privacy
Everything runs locally and makes no network calls. Invoice data never leaves your machine unless you explicitly ask for it.

## Requires

- Python 3.10+ with pypdf and openpyxl
- Optional: Google account (Gmail → Google Sheets automation mode)
- Optional: Tesseract OCR with Spanish language pack (scanned PDFs only)
- Optional: Poppler utils (scanned PDFs only)

Install the Python packages with: pip install pypdf openpyxl. On macOS: brew install tesseract tesseract-lang poppler.

## Known limitations

Scanned PDFs need Tesseract and Poppler installed locally, and OCR quality depends on the scan: unclear values are left empty and flagged, never guessed. Withholdings (e.g. IRPF) are only subtracted if you ask. Writing straight to Google Sheets needs a Sheets tool in your agent or the Gmail/Apps Script mode; otherwise you get an XLSX/CSV to import. Tested mainly with Spanish and English invoices.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Invoice PDF to Spreadsheet (OCR + Gmail automation) skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### What specific problem does this skill solve for my accounting workflow?

This skill automates the extraction of data from PDF invoices, receipts, and bills, converting them into structured spreadsheet rows. It handles both digital and scanned files using OCR to ensure no manual typing is required.

### What kind of output files and data fields should I expect?

A CSV or XLSX ledger (new or your existing one, keeping its columns) with: invoice number, date (ISO), issuer and client names with tax IDs, description, subtotal, tax, total, currency, source file and a needs_review flag, plus any columns your classification rules add. If your agent has a Google Sheets tool it can write the rows there instead; the Gmail automation mode writes to Google Sheets directly.

### Are there any specific software requirements to use the OCR or automation features?

To process scanned invoices or photos, you must have Tesseract OCR installed locally. For automated email logging, you will need a Gmail account to use the provided Apps Script template.

### How does the skill handle duplicate invoices if I process the same folder twice?

This skill includes a duplicate prevention mechanism that checks your existing ledgers by issuer and invoice number. If an invoice has already been logged, the skill will skip it to ensure your records remain accurate.

### Are there any types of tax calculations or languages that the skill cannot handle?

The skill currently does not support automatic withholding (IRPF) calculations unless you specifically request it. Additionally, while it supports any language, it has been most extensively tested with Spanish and English invoices.

### How do I instruct my AI agent to start processing my invoices?

You can tell your agent to process a specific folder of PDFs or ask it to set up a Gmail automation to log incoming bills. You can also provide custom classification rules if you want to map certain suppliers to specific cost centers.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
