Extract PDF & Image Text into CSV Using n8n and Vertex AI

Learn how to automatically extract text from PDFs and images using n8n with Google Vertex AI and Openrouter, converting costly manual entry into CSV files for easy data analysis. This workflow saves hours by automating text extraction and classification of transactions in bank statements.
googleDriveTrigger
switch
googleDrive
+5
Learn how to Build this Workflow with AI:
Workflow Identifier: 1367
NODES in Use: Google Drive Trigger, Switch, Google Drive, ExtractFromFile, HTTP Request, ConvertToFile, chainLlm, lmChatGoogleGemini

Press CTRL+F5 if the workflow didn't load.

Visit through Desktop for Best experience

Opening Problem Statement

Meet Sarah, a small business accountant who spends hours every week manually extracting transaction data from bank statement PDFs and images she receives from clients. The process is tedious, error-prone, and slows down payroll and accounting updates. Sarah needs a reliable way to automate extracting text from these financial documents and transform that data into structured CSV files she can import into her accounting software — without spending countless dollars on expensive OCR tools or manual data entry clerks.

On average, Sarah wastes 6 hours weekly extracting data, leading to delayed reports and occasional data entry mistakes that cost her clients money. If only she could automate this workflow seamlessly for PDFs and images stored on Google Drive.

What This Automation Does

This n8n workflow integrates Google Drive, Vertex AI, Openrouter, and AI language models to automate the extraction of transaction data from PDFs and images into CSV, categorizing expenses automatically.

  • Monitors a specific Google Drive folder for new PDFs or images containing bank statements or receipts.
  • Downloads files—either PDFs or image formats—whenever they are added to the folder.
  • Routes files based on type (PDF or image) to the appropriate extraction method.
  • Extracts raw text from PDFs using n8n’s built-in PDF data extractor and images using Google’s Vertex AI with Vision capabilities.
  • Sends extracted text to AI via Openrouter using the Meta LLaMA 3.1 model for intelligent analysis and CSV conversion, adding categorized columns based on transaction data.
  • Converts AI response to CSV files and saves them back to a dedicated Google Drive folder for further use.

This workflow saves Sarah at least 6 hours weekly by eliminating manual extraction, reducing data errors, and ensuring consistent, categorized transaction CSV outputs ready for her accounting tools.

Prerequisites ⚙️

  • Google Drive account with Service Account credentials — to monitor, download, and upload files securely.
  • Google Cloud Project with Vertex AI enabled 🔐 — to perform text extraction from images using Google’s advanced AI vision model.
  • Openrouter API account 🔑 — to utilize Meta LLaMA 3.1 AI conversational model for parsing, categorizing, and converting extracted text into CSV format.
  • n8n account ⚙️ — for orchestrating the workflow automation.
  • Optional: You can self-host n8n for more control — Learn more about self-hosting n8n here.

Step-by-Step Guide

Step 1: Set Up Your Google Drive Folder Trigger

In n8n, add a Google Drive Trigger node named “Get PDF or Images”.

  • Navigate to the node, select fileCreated as the event type to watch for new files.
  • Choose a specific folder ID to monitor files added there (use your bank statement folder).
  • Authenticate using your Google Service Account credentials.
  • Visual: You should see the folder path and trigger set to check every minute.

    Outcome: The workflow triggers automatically when a new PDF or image is added.

    Common Mistake: Forgetting to share the folder with the service account email address will block access.

Step 2: Route Files Based on MIME Type

Add a Switch node called “Route based on PDF or Image”.

  • Configure rules to check the mimeType property from the trigger output.
  • Set to route to “pdf” if it equals application/pdf.
  • Set to route to “image” if the MIME type contains “image/” (covers PNG, JPEG, etc).
  • Outcome: Incoming files are directed to the proper processing node.

    Common Mistake: Incorrect MIME string match causing files to be skipped.

Step 3: Download PDF and Image Files

Use two Google Drive nodes – “Download PDF” and “Download Image” with operation set to download.

  • In both nodes, use the file ID from the trigger node dynamically {{$json.id}}.
  • Authenticate via the same Google Service Account.
  • Outcome: Files are downloaded locally in the workflow for further processing.

    Common Mistake: Not setting the operation to “download” will cause wrong output format.

Step 4a: Extract Text from PDFs Using n8n’s ExtractFromFile

Add an ExtractFromFile node named “Extract data from PDF”.

  • Set the operation to pdf.
  • Connect the output of “Download PDF” to this node.
  • Outcome: Extracted raw text content from the PDF is output.

    Common Mistake: Not correctly wiring the input can cause no data extraction.

Step 4b: Extract Text from Images Using Vertex AI

Use @n8n/n8n-nodes-langchain.chainLlm, named “Vertex A.I. extract text”.

  • Send the downloaded image binary data to Vertex AI.
  • The prompt instructs Vertex AI to extract transaction data and output CSV with categorized columns.
  • Requires prior activation of Vertex AI and permissions on your Google Cloud Service Account.
  • Outcome: Image-based transaction data extracted as structured text.

    Common Mistake: Not enabling Vertex AI API or lacking correct IAM roles.

Step 5: Send Extracted PDF Text to Openrouter AI

Add an HTTP Request node called “Send data to A.I.”.

  • Uses POST method to https://openrouter.ai/api/v1/chat/completions.
  • Body contains the LLaMA model and a message prompt instructing to parse the raw PDF text to CSV with categorization.
  • Set up header authentication with your Openrouter API key.
  • Outcome: Clean, categorized CSV text extracted from PDF text.

    Common Mistake: Wrong API key or header format will cause authorization errors.

Step 6: Convert AI Response to CSV File

Use the ConvertToFile node to change AI JSON response text into CSV format file.

This applies both for PDF and image outputs (separate nodes “Convert to CSV” and “Convert to CSV2”).

Outcome: You get actual CSV files ready to upload or download.

Step 7: Upload CSV to Google Drive

Finally, upload the resulting CSV files to a designated folder in Google Drive using the Google Drive node.

  • Set “name” to be the current date.
  • Choose your drive and folder ID where you want CSV files stored.
  • Authenticate using the same Google Service Account.
  • Outcome: Your automated CSV exports are safely stored and accessible.

    Common Mistake: Using wrong folder ID or forgetting folder permissions will block uploads.

Customizations ✏️

  • Change AI Model: In the “Send data to A.I.” HTTP node, replace the Meta LLaMA model with OpenAI GPT-4 or Google Gemini model if you want stronger or cheaper parsing options.
  • Add More File Types: Extend the Switch node to support TIFF or HEIC image MIME types by adding additional ‘contains’ conditions for image MIME types.
  • Add Transaction Filters: Inject a Function node after extraction to filter transactions by date or amount before conversion to CSV.
  • Rename Output Files: Customize the “Upload to Google Drive” node to add client names or bank names dynamically to filenames using expressions like {{$json.clientName}}.
  • Enable Email Notifications: Add a Gmail node after upload to notify users when a CSV is ready for review.

Troubleshooting 🔧

  • Problem: “Google Drive Trigger fires but no file is processed.”

    Cause: Folder sharing permissions missing for service account.

    Solution: Share the Google Drive folder with the service account email under Drive settings 1
  • Problem: “ExtractFromFile node outputs empty text.”

    Cause: Unsupported or scanned PDF not containing extractable text layer.

    Solution: Verify PDF has selectable text or use the image extraction route.
  • Problem: “Vertex AI extraction fails with permission errors.”

    Cause: Missing Vertex AI API enablement or IAM roles.

    Solution: Enable Vertex AI in Google Cloud console and add roles to your service account.
  • Problem: “Openrouter API call returns 401 Unauthorized.”

    Cause: Incorrect API key or header authorization format.

    Solution: Double-check header auth configuration with your token.

Pre-Production Checklist ✅

  • Confirm Google Drive folder is shared with service account email.
  • Test Google Drive file upload triggers the workflow.
  • Verify API keys and authentications for Openrouter and Google Cloud services.
  • Upload test PDF and image files resembling bank statements.
  • Confirm AI extraction nodes output expected CSV data strings.
  • Ensure CSV files upload successfully to target Google Drive folder.

Deployment Guide

Once tested, activate this workflow in your n8n account by turning the toggle to ON.

Keep an eye on execution logs for errors or failed runs.

Configure alerting via n8n or email nodes if needed for production monitoring.

FAQs

  • Can I use other AI models besides Meta LLaMA?
    Yes, you can switch to OpenAI GPT models or Google Gemini by changing the HTTP request node or using the Google Gemini Chat node already present.
  • Does this workflow consume a lot of API credits?
    Mostly on Openrouter and Google Vertex AI calls; monitor costs via your respective dashboards.
  • Is my data secure?
    All credentials are stored securely in n8n; data flows only through trusted APIs with authentication.
  • Can it handle large volumes of files?
    Yes, but you may need to increase workflow concurrency and handle rate limits in Google Drive and Openrouter APIs.

Conclusion

By following this detailed guide, you have automated the extraction of transaction data from PDFs and images stored in Google Drive, converting them into clean, categorized CSV files using n8n, Google Vertex AI, and Openrouter’s Meta LLaMA model.

This saves you significant time—potentially over 6 hours weekly—and reduces costly human errors in data entry. As a next step, consider automating email notifications for completed CSVs or integrating this CSV output directly with your accounting or ERP systems for end-to-end automation.

With these tools, tedious manual extraction is a thing of the past. Let’s make your finance workflows smarter and faster!

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation in n8n (Beginner Guide)

A complete beginner guide to building an AI-powered SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free