Bank Statement PDF to Markdown with Deposit Extraction via Gemini Vision

Overview

This workflow automates the conversion of bank statement PDFs (including scanned images) into structured markdown text, then extracts deposit line items using Google Gemini's vision capabilities. It's ideal for financial assistants, personal finance trackers, or any workflow that needs to parse bank statements without manual data entry.

By combining a PDF-to-image converter with a multimodal LLM, the workflow handles both digital and scanned PDFs, preserving complex table layouts that traditional OCR often struggles with.

Steps in Detail

  1. When clicking ‘Test workflow’ (Manual Trigger) — Starts the workflow manually for testing. No authentication required.
  2. Get Bank Statement (Google Drive, OAuth2) — Downloads a PDF file from Google Drive using a specified file ID. You need a Google Drive account and OAuth2 credentials in n8n.
  3. Split PDF into Images (HTTP Request, No Auth) — Sends the PDF to a Stirling PDF service (default: http://stirling-pdf:8080/api/v1/convert/pdf/img) to convert each page into a JPG image at 300 DPI. Returns a ZIP file. For sensitive data, self-host Stirling PDF.
  4. Extract Zip File (Compression, No Auth) — Unzips the downloaded ZIP into individual image files.
  5. Images To List (Code, No Auth) — JavaScript code that iterates over binary items and creates a list of objects, each containing a file name and binary data – one per image page.
  6. Sort Pages (Sort, No Auth) — Sorts the images alphabetically by file name to maintain page order.
  7. Resize Images For AI (Edit Image, No Auth) — Resizes each image to 75% of original size using percentage scaling to reduce token usage while retaining sufficient resolution for vision.
  8. Google Gemini Chat Model (AI Language Model, API Key Auth) — Configures the Gemini 1.5 Pro model (model models/gemini-1.5-pro-latest). Requires a Google AI Studio API key or OAuth credentials.
  9. Transcribe to Markdown (Chain LLM, uses Gemini Chat Model) — Sends each image to Gemini with a system prompt: “transcribe the image to markdown.” The prompt instructs the model to faithfully capture all text, tables (convert to markdown tables), and replace graphics with descriptions (e.g., scanned checks replaced with <scanned image of check>). Outputs markdown text per page.
  10. Combine All Pages (Aggregate, No Auth) — Joins all page transcriptions into a single string with --- separators, stored in a field named pages.
  11. Google Gemini Chat Model1 (Second Gemini model, API Key Auth) — Same model as step 8, used here for the Information Extractor.
  12. Extract All Deposit Table Rows (Information Extractor, uses Gemini Chat Model1) — Takes the combined markdown and a JSON schema to extract deposits. The system prompt asks: “This statement contains tables with rows showing deposit and withdrawal… What are the deposits to the account found in this statement?” Outputs an array of objects with date, description, and amount.

Setup Instructions

  • Google Drive: You need a Google Drive account. In n8n, create OAuth2 credentials for Google Drive (see n8n Google Drive node docs).
  • Stirling PDF: The workflow uses a public endpoint; for production or sensitive data, self-host Stirling PDF and update the URL in the HTTP Request node.
  • Google Gemini: Obtain an API key from Google AI Studio (free tier available). In n8n, create credentials of type “Google Gemini API” and select “API Key” as the authentication method.

Use Cases & Variations

  • Personal Finance: Automatically pull deposits into a spreadsheet or notify you of large deposits.
  • Invoice Processing: Adapt the system prompt and schema to extract invoice line items.
  • Document Digitisation: Replace the Google Drive source with a webhook or email trigger to process PDFs on the fly.
  • Other LLMs: Swap Gemini for OpenAI GPT‑4o or Anthropic Claude if preferred (adjust credentials and model name accordingly).
20 nodesmanual triggerFinance
Lm Chat Google GeminiSortSticky NoteGoogle DriveHTTP RequestCompressionCodeEdit Image

Workflow JSON

{
  "meta": {
    "instanceId": "408f9fb9940c3cb18ffdef0e0150fe342d6e655c3a9fac21f0f644e8bedabcd9"
  },
  "nodes": [
    {
      "id": "490493d1-e9ac-458a-ac9e-a86048ce6169",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -700,
        260
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "116f1137-632f-4021-ad0f-cf59ed1776fd",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        980,
        440
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-1.5-pro-latest"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "dSxo6ns5wn658r8N",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "44695b4f-702c-4230-9ec3-e37447fed38e",
      "name": "Sort Pages",
      "type": "n8n-nodes-base.sort",
      "position": [
        400,
        320
      ],
      "parameters": {
        "options": {},
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "fileName"
// ... truncated (copy to see full JSON)

How to Import This Workflow

  1. 1Copy the workflow JSON above using the Copy Workflow JSON button.
  2. 2Open your n8n instance and go to Workflows.
  3. 3Click Import from JSON and paste the copied workflow.

Don't have an n8n instance? Start your free trial at n8nautomation.cloud

Related Templates

AI-Powered Auto-Healing for Failed n8n Workflows

High-Level Summary This workflow automates the entire overdue invoice recovery process using an AI agent. It runs daily on a schedule, reads unpaid invoices from a Google Sheet, and for each invoice uses OpenAI's GPT-4o-mini to analyze the situation and generate a personalized, context-aware recovery email. The email is sent via Gmail, and if the AI determines the account requires escalation (legal or collections), an internal alert is emailed to your legal team. The workflow then updates the invoice sheet with the new escalation level and appends a detailed log row to a separate recovery sheet for full auditability. Slack alerts notify the team if no invoices are found or if the AI encounters an error. Nodes and Their Functions Below is every node in the workflow, listed in execution order, with its type, authentication method, and key configuration. Daily Invoice Check (Schedule Trigger, No auth) — Fires the workflow every 24 hours. Configured with an interval rule of 24 hours. Read Overdue Invoices (Google Sheets, OAuth2) — Reads all rows from the "invoices" tab of your Google Sheet. Requires a Google Sheets OAuth2 credential and the spreadsheet ID. Any Overdue Invoices? (If, No auth) — Checks if the field is not empty. If invoices exist, the workflow proceeds to the AI agent; otherwise, it triggers a Slack alert. Slack: No Invoices Found Alert (Slack, OAuth2) — Sends a message to a specified Slack channel when no overdue invoices are found. Uses Slack OAuth2 credential. AI Recovery Agent (LangChain Agent, uses OpenAI API key via sub-node) — The core AI node. It receives each invoice row and a system prompt instructing it to act as an AR recovery specialist. It outputs a JSON object with escalation level, subject, email body, payment plans, and escalation action. The agent is connected to the GPT-4o-mini Language Model node. GPT-4o-mini Language Model (OpenAI Chat Model, API Key) — Provides the language model for the AI agent. Uses the model. Requires an OpenAI API key credential. Parse & Structure AI Response (Code, No auth) — A JavaScript code node that cleans and parses the AI's raw output into a structured JSON object. It also merges the original invoice data (invoice number, client name, etc.) into the output. Send Recovery Email to Client (Gmail, OAuth2) — Sends the personalized recovery email to the client. Uses the and from the AI response. The recipient email is taken from the original invoice row. Requires a Gmail OAuth2 credential. Needs Escalation? (If, No auth) — Checks if the field from the AI response is not "none". If escalation is needed, the workflow sends an internal alert; otherwise, it skips directly to logging. Send Escalation Alert to Legal Team (Gmail, OAuth2) — Sends an HTML email to a predefined legal team address with details about the high-risk invoice. The email includes client name, invoice number, amount due, days overdue, escalation level, and AI summary. Requires a Gmail OAuth2 credential. Update Invoice Status in Sheet (Google Sheets, OAuth2) — Updates the original invoice row in the "invoices" tab with the new escalation level and AI summary. Uses the row number to match the correct row. Append Row to Recovery Log (Google Sheets, OAuth2) — Appends a new row to the "Recovery sheet" tab with a full log of the action taken, including invoice details, AI subject, summary, escalation level, and Gmail label IDs. Slack: AI Error Alert (Slack, OAuth2) — Triggered if the AI Recovery Agent node encounters an error. Sends a Slack message with the invoice number and a request to check execution logs. Additionally, there are several Sticky Notes (Overview, Section: Trigger, Section: AI Agent, Section: Email, Section: Logging, Section: Security) that serve as documentation and visual guides within the editor. Setup Instructions To use this workflow, you need the following accounts and credentials: Google Sheets — A spreadsheet with two tabs: - : Columns should include Invoice, Client, Email, Amount, Due Date, Days Overdue, Level, Reminders Sent, and optionally row_number. - : Columns for logging (Invoice, Client, Amount, Days Overdue, Level, Email, escalation_level, summary, subject, labelIds). Create a Google Sheets OAuth2 credential in n8n and connect it to both Google Sheets nodes. Gmail — A Gmail account for sending recovery emails and escalation alerts. Create a Gmail OAuth2 credential in n8n. Update the escalation email recipient address () to your legal or collections team's email. OpenAI — An OpenAI API key with access to the model. Create an OpenAI API credential in n8n. Slack — A Slack workspace and a channel for alerts. Create a Slack OAuth2 credential in n8n. Replace with the actual channel ID. After connecting credentials, update the Google Sheet ID in the "Read Overdue Invoices", "Update Invoice Status in Sheet", and "Append Row to Recovery Log" nodes. Also update the Slack channel IDs and the legal team email address. Then activate the workflow. Use Cases and Variations Custom Escalation Rules — Modify the AI prompt or the "Needs Escalation?" condition to use different criteria (e.g., amount threshold, client tier). Multi-language Support — Adjust the AI prompt to generate emails in different languages. Integration with Accounting Software — Replace the Google Sheets nodes with API calls to QuickBooks, Xero, or other invoicing platforms. Different AI Models — Swap the GPT-4o-mini model for another OpenAI model or use a different provider via the LangChain integration. SMS or Other Channels — Add Twilio or other nodes to send reminders via SMS in addition to email. Dashboard & Reporting — Extend the logging sheet to feed into a BI tool for real-time recovery metrics.

19 nodes

Investment Portfolio Email Report from Baserow and Tradegate

Summary This workflow automatically fetches your stock portfolio from a Baserow table, retrieves current bid prices from Tradegate (a German stock exchange), calculates current values and changes, and emails an HTML report via SendGrid. It runs on a schedule (Monday to Saturday at 07:15) or can be triggered manually. Perfect for private investors tracking their holdings and receiving a daily digest. How It Works Triggers: You have two triggers: a Cron node for scheduled runs and a Manual Trigger for on-demand execution. Both feed into the same workflow. Fetch stocks: The Baserow node reads all rows from a specified table (database 146, table 680). Each row contains a stock's ISIN, name, purchase price, and count. Get live prices: For each stock, the HTTP Request node calls (no authentication required) and returns the page as a string. Extract data: The HTML Extract node scrapes specific CSS selectors to pull out the current bid, ask, currency, name, WKN, and ISIN. Enrich and format: The Set node (Format result) combines the extracted data with original Baserow values, calculates the current value (bid × count), and keeps only the relevant fields. A second Set node (Calculate change) computes absolute and percentage change from the purchase price. Build email: The Function node (Build HTML) generates a clean HTML table with all rows, a total portfolio value, and the workflow ID. The timestamp is formatted for Europe/Dublin. Send report: The SendGrid node emails the generated HTML to your inbox (subject: "Investment report"). Node Breakdown with Auth Methods Cron (n8n-nodes-base.cron, No auth) — Runs the workflow at 07:15 Monday to Saturday (custom cron expression: ). On clicking 'execute' (n8n-nodes-base.manualTrigger, No auth) — Manual trigger for testing or ad-hoc runs. Baserow (n8n-nodes-base.baserow, API Key auth) — Reads all rows from Baserow table 680 in database 146. Requires a Baserow account and API key. Fetch tradegate stock page (n8n-nodes-base.httpRequest, No auth) — Sends a GET request to with a query parameter (taken from the Baserow row). Response is treated as a string. Parse tradegate stock page (n8n-nodes-base.htmlExtract, No auth) — Uses CSS selectors to extract: WKN, ISIN, Currency, Name, Bid, Ask from the returned HTML. Format result (n8n-nodes-base.set, No auth) — Keeps only the fields: Name, ISIN, Count (from Baserow), Purchase Price (from Baserow), and Current Value (calculated as ). Set to keep only these. Calculate change (n8n-nodes-base.set, No auth) — Adds two new fields: (Current Value - Purchase Price) and (percentage difference). Build HTML (n8n-nodes-base.function, No auth) — Custom JavaScript code that takes all items and constructs a styled HTML table with a total sum and a footer. SendGrid (n8n-nodes-base.sendGrid, API Key auth) — Sends an email with subject "Investment report", from/to , content type HTML, and body from the field. Setup Instructions Baserow: Create a Baserow database and table with columns for , , , . Add your stock holdings. In n8n, create Baserow credentials (API key) and set the database ID and table ID (here: 146 and 680). SendGrid: Set up a SendGrid account and obtain an API key. Create credentials in n8n. Update the and fields to your desired addresses (the workflow currently uses ). Tradegate: No credentials needed — the workflow queries the public order book page. Test: Click the "On clicking 'execute'" node to run once and verify email delivery. Use Cases & Variations Personal portfolio tracker: Replace Baserow with your own data source (e.g., Google Sheets, Airtable) to track any assets. Price alerts: Modify the email HTML to highlight large percentage changes or include thresholds. Multi-currency support: Extract currency and apply conversion rates. Add charts: Integrate a charting library (like Chart.js) in the HTML function for visual representation. Slack instead of email: Swap SendGrid for a Slack node to send the report to a channel. Different exchanges: Adjust the URL and CSS selectors to fetch from other sources (e.g., Finanzen.net, Yahoo Finance).

9 nodes

AI Expense Tracker: Save Chat Messages to Google Sheets via n8n Chat

Overview This workflow turns your natural language expense entries into structured data and saves them to a Google Sheet. When you send a chat message like "car wash; 59.3 usd; 25 jan 2024" via the built-in n8n chat interface, the AI agent (powered by OpenAI) parses the text, extracts cost, description, and date, then triggers a sub-workflow that appends a new row in a Google Sheet. This is perfect for quick, conversational expense logging without manual data entry. Node Breakdown When chat message received (Chat Trigger) — No auth (n8n built-in webhook) — Listens for incoming chat messages from the n8n chat interface. No external credentials needed. AI Agent (@n8n/n8n-nodes-langchain.agent) — Uses the OpenAI Chat Model (API Key auth) and Window Buffer Memory (no auth). It receives the chat input, uses a system message instructing it to use the "saveexpensein_db" tool, and responds with a confirmation message. OpenAI Chat Model (OpenAI) — API Key auth — Connects to OpenAI's GPT model to process the chat message. Configured with default options. Window Buffer Memory (Memory) — No auth — Maintains conversation context across messages (buffer window). Parse msg and save to Sheets (Tool Workflow) — No auth (calls the same workflow as sub-workflow) — This is a tool that the AI agent can call. It passes the chat input to the sub-workflow's input trigger. The tool name is "saveexpensein_db". Workflow Input Trigger (Execute Workflow Trigger) — No auth — Receives the input from the tool call and passes it to the next node. Expense text to JSON parser (Information Extractor) — Uses OpenAI Chat Model1 (API Key auth) — Extracts structured data from the input text. It defines attributes: cost (number), desc (string), date (date). The prompt instructs to convert the expense text to JSON. OpenAI Chat Model1 (OpenAI) — API Key auth — Provides the language model for the information extractor. Save expense into Google Sheets (Google Sheets) — OAuth2 auth — Appends a new row to a Google Sheet. The sheet is specified by document ID and sheet name. Columns are mapped: msg (original input), cost, date, desc. Uses append operation. Sticky Note — No auth — Contains setup instructions for the user. Setup Instructions **Google Sheets: Create a copy of the expense template (File → Make a copy). Note the new spreadsheet ID. OpenAI API Key: Obtain an API key from OpenAI and add it as a credential in n8n for the OpenAI Chat Model nodes. Google Sheets Credential: Set up OAuth2 credential in n8n for Google Sheets with access to the spreadsheet. Sub-workflow reference: Open the "Parse msg and save to Sheets" node and ensure the workflow dropdown points to this same workflow (it should auto-select the current workflow). Activate the workflow to enable the chat trigger. Then send a message like "car wash; 59.3 usd; 25 jan 2024" to the chat interface. You'll receive a confirmation and a new row will appear in your Google Sheet. Use Cases & Variations Personal expense tracking: Log daily expenses on the go via chat. Team expense reports: Modify the Google Sheet to include employee names or categories. Multi-language support: The AI can parse expenses in different languages. Add receipt images: Extend the workflow with an image-to-text node to extract data from photos. Integrate with accounting software: Replace Google Sheets with a database or API call to QuickBooks, Xero, etc.

10 nodes

Ready to automate with n8n?

Get affordable managed n8n hosting with 24/7 support.