Multi-Page PDF OCR and AI Data Extraction to Google Sheets - n8n Workflow

Automate Thai multi-page PDF processing using Typhoon OCR and LLMs. This n8n workflow extracts data, structures it, and saves the results to Google Sheets.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Businesses needing high-accuracy OCR for Thai documents and batch processing capabilities.
Users looking for advanced document parsing n8n templates utilizing command-line tools and AI.
Developers implementing complex file handling and external API integrations within an n8n workflow.
Teams required to automate data entry from archival PDF scans into structured spreadsheets.

Overview

This sophisticated n8n workflow solves the major challenge of batch processing complex, multi-page PDF documents, especially those containing non-English content like Thai text. It begins by retrieving multiple PDFs from a defined directory. The core process uses file system operations to split each multi-page file into individual pages, ensuring high-accuracy text extraction via the dedicated Typhoon OCR service, integrated through a custom Python script execution command n8n node. After successful OCR, the text from all pages of a single document is aggregated. This raw, unstructured text is then passed to an LLM (Large Language Model) via an n8n node to impose a strict, predefined structure (identifying key fields like dates, book IDs, and subjects). Finally, the structured data is seamlessly appended as a clean row to Google Sheets. This comprehensive n8n workflow demonstrates an advanced integration strategy leveraging code, command execution, cloud storage, and AI within a single, robust automation flow, making it a valuable addition to your n8n templates library.

How it Works

The process starts with the manual n8n trigger, which immediately initiates the Load PDFs from doc Folder n8n node, pulling all target PDF files from the designated directory (/doc/multipage).

The Loop Over Items n8n node ensures that every detected PDF file is processed sequentially, handling the batch nature of the task. Inside the loop, the file is temporarily written to disk, and the SetInputPath n8n node prepares the required path variables.

File separation is handled by the Split PDF page execution command n8n node, which uses the underlying operating system's pdfseparate tool to break the multi-page PDF into single-page files in a temp folder.

The Read Splite PDF Page n8n node loads these temporary page files. The core extraction is performed by the Extract Text with Typhoon OCR n8n node, which runs a custom Python script that utilizes the Typhoon OCR API on each individual page, returning the raw text.

The results from all pages are consolidated using the Aggregate n8n node, merging the text into one complete document string.

This aggregated text is sent to the Structure Text to JSON with LLM n8n node, powered by an LLM via OpenRouter, which uses a defined prompt to transform the unstructured Thai text into a clean JSON object.

The custom Parse JSON to Sheet Format code n8n node cleans up the LLM's output and flattens the structured JSON fields (like book_id, date, to) into a single row format required for the spreadsheet.

Finally, the Save to Google Sheet n8n node appends the structured record to the specified Google Sheets document.

The n8n workflow concludes with the Clear tmp files execution command n8n node, which handles essential cleanup, removing temporary files and moving the original processed PDF to a 'Completed' directory.

Installation Guide

Importing the n8n Workflow: Copy the provided JSON data and import it into your n8n instance using the import functionality.
Credential Setup:
Google Sheets: You must configure the OAuth2 API credentials for Google Sheets, ensuring the account has necessary write permissions to the target spreadsheet specified in the Save to Google Sheet n8n node.
OpenRouter: Set up OpenRouter API credentials required for the LLM n8n node to enable AI processing.
External Dependencies & OCR Key: This n8n workflow relies on command-line tools like pdfseparate (part of poppler-utils) and the Python environment. Ensure these are installed in your n8n environment. Crucially, update the Extract Text with Typhoon OCR n8n node command with your actual Typhoon OCR API key where the placeholder is located.
Folder Structure: Verify that the /doc/multipage and /doc/tmp file paths are correctly accessible mounted volumes within your n8n setup, allowing the file operations to run successfully.

Node Details

When clicking ‘Test workflow’ (Manual Trigger n8n trigger): The starting point for execution, useful for testing the entire complex n8n workflow logic.
Load PDFs from doc Folder (Read/Write File n8n node): Function: Reads the list of PDF files stored in the source folder (/doc/multipage).
Loop Over Items (Split In Batches n8n node): Function: Manages iteration, ensuring the subsequent steps of the n8n workflow process one multi-page PDF document completely before moving to the next.
Split PDF page (Execute Command n8n node): Function: Uses a shell command (pdfseparate) to break the multi-page PDF into single-page files, which is critical for accurate, localized OCR processing.
Extract Text with Typhoon OCR (Execute Command n8n node): Function: Runs an embedded Python script calling the external Typhoon OCR service for high-accuracy text extraction on each split page. Key Configuration: Requires updating the placeholder API key.
Aggregate (Aggregate n8n node): Function: Combines the raw text extracted from all individual pages of the document back into a single, cohesive text block ready for AI processing.
Structure Text to JSON with LLM (LLM Chain n8n node): Function: Passes the aggregated Thai text and a structuring prompt to the LLM to generate a predefined JSON schema of the document's key information.
OpenRouter Chat Model (LLM n8n node): Function: Provides the computational power for the AI structuring step, configured to use openai/gpt-4o-mini for cost-effective accuracy.
Parse JSON to Sheet Format (Code n8n node): Function: Customizes the LLM's JSON output, cleaning up markdown formatting and flattening nested objects to align perfectly with the column structure of Google Sheets.
Save to Google Sheet (Google Sheets n8n node): Function: Appends the final, structured data row to the target spreadsheet.


  • Clear tmp files (Execute Command n8n node): Function: Final step to clean the workspace, deleting temporary pages and archiving the successfully processed source PDF to a 'Completed' folder.

Related n8n Workflows

Free

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

Project Manager who passionate about Automation & AI and continuously explore innovative ways to improve business processes through intelligent workflow automation. Let’s connect and automate the future!

Featured*