Smart Document Parser for Invoices, Logs or Sensor Reports - n8n Workflow

Automate data extraction from uploaded PDFs, images, and CSVs using an n8n workflow powered by Google Gemini AI and OCR. Save structured invoice or report data directly to Google Sheets.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Finance and Accounting Teams: Users who need to automate processing high volumes of invoices and receipts.
Data Engineers: Professionals looking for robust n8n templates to handle mixed-format file inputs (PDF, Image, CSV).
Automation Specialists: Anyone leveraging the power of AI (Google Gemini) within an n8n workflow for complex data transformation.
Operations Managers: Users needing to digitize and standardize sensor logs or external reports captured as images or PDFs.

Overview

Manual data entry from invoices, logs, or reports is time-consuming and prone to errors. This specialized n8n workflow solves this by providing a unified, AI-powered pipeline capable of handling multiple file formats—including scanned images and PDFs—and converting them into clean, structured data in Google Sheets.

The core value of this n8n template lies in its versatility. It utilizes OCR for images, built-in PDF extraction for digital documents, and then passes the resulting text to the Google Gemini Chat Model (a sophisticated LLM) via an n8n node. This ensures accurate field extraction (like invoiceid, total, and vendorname), regardless of the document layout. Setting up this complete n8n solution drastically reduces manual effort and improves data quality.

How it Works

This efficient n8n workflow begins when a document is uploaded, functioning via a series of logical steps:


  1. Trigger: The process starts with the Webhook Invoice upload n8n trigger, configured to accept POST requests containing the document file.

  2. File Type Check: The Check file type Switch n8n node inspects the uploaded file's MIME type, routing the data accordingly (Image, PDF, or CSV).

  3. Data Extraction:

If the file is an Image, the Image to Text n8n node (Tesseract OCR) performs Optical Character Recognition to convert the image content into raw text.
If the file is a PDF, the PDF to Text n8n node extracts the embedded text.
* If the file is a CSV, the CSV to JSON n8n node parses the file directly into a usable data structure.

  1. AI Formatting (Image/PDF Path): The extracted text is passed to the LangChain Format data from text n8n node, which utilizes the Google Gemini Chat Model. A carefully constructed prompt instructs the AI to identify specific fields (invoice date, total, currency, etc.) and return the output as a strict JSON string.

  2. Data Transformation: The Transfrom data Code n8n node sanitizes the raw AI output (removing any markdown fences like ``json) and converts the resulting string into a true JSON object, ready for database insertion.

  3. Storage: The structured data is finally appended to the designated Google Sheet using the Google Sheets n8n node (or Invoice data node for CSV files), matching or updating records based on the invoice_id` field. This robust n8n automation template ensures continuity and accuracy.

Installation Guide

To deploy this powerful document parsing n8n workflow, follow these steps:


  1. Import: Copy the provided JSON code and import it directly into your n8n instance.

  2. Credentials Setup: You will need to set up credentials for the following services:

Google Sheets OAuth2 API: Connect your Google account, ensuring n8n has permission to read and write to your Google Drive and Sheets.
Google Gemini / Google Palm API: Provide your API key for the Google Gemini Chat Model. This is crucial for the LLM processing n8n node.

  1. Webhook Configuration: Activate the Webhook Invoice upload n8n trigger node. Copy the generated test or production URL.

  2. Google Sheets Node Setup: In both Google Sheets n8n node instances (Invoice Data and Invoice data):

Select the appropriate Google Spreadsheet Document ID.
Specify the Sheet Name (e.g., 'Invoice') where the extracted data will be logged.

  1. Testing: Send a PDF, image file (e.g., JPEG or PNG invoice), or CSV file via a POST request to the webhook URL to test the full n8n workflow execution.

Node Details

Webhook Invoice upload (n8n trigger): The entry point for the n8n workflow. Configured for POST requests at the /uploadDoc path to receive the binary file data.
Check file type (Switch n8n node): Essential flow control. Routes the binary file based on its MIME type (image, application/pdf, or csv) to the correct extraction path, making this n8n workflow highly versatile.
Image to Text (Tesseract n8n node): Performs OCR on image files to convert visual characters into extractable text.
PDF to Text & CSV to JSON (ExtractFromFile n8n node): Built-in utility nodes for quickly extracting text from PDFs and parsing CSV content into data.
Google Gemini Chat Model (LLM Provider): Provides the large language model capability to the LLM Chain n8n node. It analyzes the raw text to intelligently identify invoice fields.
Format data from text (LangChain Chain n8n node): The core intelligence step. It uses a specific prompt template to guide the Gemini model, ensuring the output is a clean JSON object containing nine predefined fields (e.g., total, invoiceid).
Transfrom data (Code n8n node): Cleans up the AI's output string and uses JSON.parse to convert it into a structured JSON data item, ensuring reliable input for the downstream n8n node.
Invoice Data / Invoice data (Google Sheets n8n node): The final action. Configured using the appendOrUpdate operation to write the parsed data into the designated spreadsheet, matching existing rows by invoice
id to prevent duplicates. This is the output step of the entire n8n workflow.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by

A Leading Software Engineering, Consulting & Outsourcing Services Company in USA & India serving Clients Globally since 1999.

Featured*