AI驱动的PDF发票解析器 - Google Drive、Google Sheets和OpenAI
这是一个Finance, AI领域的自动化工作流,包含 10 个节点。主要使用 GoogleDrive, GoogleSheets, Agent, ExtractFromFile, GoogleDriveTrigger 等节点,结合人工智能技术实现智能自动化。 基于Google Drive、Google Sheets和OpenAI的AI驱动PDF发票解析器
- •Google Drive API 凭证
- •Google Sheets API 凭证
- •OpenAI API Key
使用的节点 (10)
{
"meta": {
"instanceId": "d1786ab0d745a7498abf13a9c2cdabb1374c006e889b79eef64ce0386b8f8a41",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "5c1a182c-3485-48db-91b2-d46f0f1d3fd5",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
560,
200
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "MGwGMKEkdcjzlYCw",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "45f94af9-147a-434c-aef5-fc3f7e60a140",
"name": "结构化输出解析器",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
780,
200
],
"parameters": {
"jsonSchemaExample": "{\n \"invoice_number\": \"\",\n \"invoice_date\": \"\",\n \"due_date\": \"\",\n \"vendor_name\": \"\",\n \"total_amount\": \"\",\n \"currency\": \"\",\n \"items\": [\n {\n \"description\": \"\",\n \"amount\": \"\"\n }\n ],\n \"tax\": \"\",\n \"category\": \"\"\n}"
},
"typeVersion": 1.2
},
{
"id": "01c8daa7-81e1-46cd-b927-f264e90391b4",
"name": "发票文件夹监视器",
"type": "n8n-nodes-base.googleDriveTrigger",
"position": [
0,
0
],
"parameters": {
"event": "fileCreated",
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"triggerOn": "specificFolder",
"folderToWatch": {
"__rl": true,
"mode": "id",
"value": "1KJ4fvXcKVMGJunsKvPYf8PkX5K9SVwFk"
}
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "SEUhrgz30NMJS3cH",
"name": "Google Drive account"
}
},
"typeVersion": 1
},
{
"id": "af299424-233a-4ac0-a92b-7f456d11e15a",
"name": "下载发票 PDF",
"type": "n8n-nodes-base.googleDrive",
"position": [
200,
0
],
"parameters": {
"fileId": {
"__rl": true,
"mode": "id",
"value": "={{ $json.id }}"
},
"options": {},
"operation": "download"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "SEUhrgz30NMJS3cH",
"name": "Google Drive account"
}
},
"typeVersion": 3
},
{
"id": "e896d679-a064-459a-8e4f-603436879cda",
"name": "PDF 文本提取器",
"type": "n8n-nodes-base.extractFromFile",
"position": [
400,
0
],
"parameters": {
"options": {},
"operation": "pdf"
},
"typeVersion": 1
},
{
"id": "f43fe296-b04b-41fd-ad4d-a845d009e80f",
"name": "发票解析 AI 代理",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
580,
0
],
"parameters": {
"text": "=You are an intelligent invoice parser. I will give you raw text extracted from a PDF invoice. \n\n========================\nSTART OF RAW INVOICE TEXT\n\n{{ $json.text }}\n\nEND OF RAW INVOICE TEXT\n========================\n\nYour job is to:\n\n1. Extract key information from the invoice such as:\n - invoice_number\n - invoice_date\n - due_date (if available)\n - vendor_name\n - total_amount\n - currency (e.g., USD, IDR, etc.)\n - items (as a list of item descriptions and their amounts)\n - tax (if available)\n\n2. Detect the invoice **category**, such as:\n - Utilities\n - Office Supplies\n - Travel\n - Software\n - Food & Beverage\n - Others (if unknown)\n\n3. Return the result in this exact JSON format:\n\n```json\n{\n \"invoice_number\": \"\",\n \"invoice_date\": \"\",\n \"due_date\": \"\",\n \"vendor_name\": \"\",\n \"total_amount\": \"\",\n \"currency\": \"\",\n \"items\": [\n {\n \"description\": \"\",\n \"amount\": \"\"\n }\n ],\n \"tax\": \"\",\n \"category\": \"\"\n}\n",
"options": {},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 1.9
},
{
"id": "00eec735-03c4-4a78-829c-54354613812a",
"name": "插入发票数据",
"type": "n8n-nodes-base.googleSheets",
"position": [
920,
0
],
"parameters": {
"columns": {
"value": {
"Tax": "={{ $json.output.tax }}",
"Items": "={{ $json.output.items }}",
"Category": "={{ $json.output.category }}",
"Currency": "={{ $json.output.currency }}",
"Due Date": "={{ $json.output.due_date }}",
"Vendor Name": "={{ $json.output.vendor_name }}",
"Invoice Date": "={{ $json.output.invoice_date }}",
"Total Amount": "={{ $json.output.total_amount }}",
"Invoice Number": "={{ $json.output.invoice_number }}"
},
"schema": [
{
"id": "Invoice Number",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Invoice Number",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Invoice Date",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Invoice Date",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Due Date",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Due Date",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Vendor Name",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Vendor Name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Total Amount",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Total Amount",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Currency",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Currency",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Items",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Items",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Tax",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Tax",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Category",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Category",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1u5dHeytao9y3L0Mgv8cSomPVLS3CMrn_eOwXW3oQ3c8/edit#gid=0",
"cachedResultName": "Invoices"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1u5dHeytao9y3L0Mgv8cSomPVLS3CMrn_eOwXW3oQ3c8",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1u5dHeytao9y3L0Mgv8cSomPVLS3CMrn_eOwXW3oQ3c8/edit?usp=drivesdk",
"cachedResultName": "PDF Invoice Parser - n8n template"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "ypmzFxQFfAacuVVC",
"name": "Google Sheets account"
}
},
"typeVersion": 4.5
},
{
"id": "78ead6a4-7ae7-4182-a7f1-eebb7f38d776",
"name": "便签 2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-320,
-100
],
"parameters": {
"color": 4,
"width": 280,
"height": 400,
"content": "## 需要设置"
},
"typeVersion": 1
},
{
"id": "45fc8d0a-c76a-4c2a-871e-19ad144993f0",
"name": "便签 3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-320,
340
],
"parameters": {
"color": 5,
"width": 460,
"height": 400,
"content": "## 🧾 基于 AI 的 PDF 发票解析器,适用于 Google Drive 和 Sheets"
},
"typeVersion": 1
},
{
"id": "d85f3e8e-38cc-4a12-9592-ce32373ddcf9",
"name": "便签 4",
"type": "n8n-nodes-base.stickyNote",
"position": [
160,
340
],
"parameters": {
"color": 5,
"width": 400,
"height": 340,
"content": "## 📋 工作流程概述"
},
"typeVersion": 1
}
],
"pinData": {
"Invoice Folder Monitor": [
{
"id": "168eK7xkg9bhZRC9Nn3aoVbeU--Cy_4ie",
"kind": "drive#file",
"name": "invoice123123.pdf",
"size": "43627",
"owners": [
{
"me": true,
"kind": "drive#user",
"photoLink": "https://lh3.googleusercontent.com/a/ACg8ocKYEvqVbfrYpVM3Esbt8CDt_Fije42MxkdcBFDBR1qni7Tgw5j7=s64",
"displayName": "Billy Christi Hartanto",
"emailAddress": "billychartanto@gmail.com",
"permissionId": "06783842879122931240"
}
],
"shared": false,
"spaces": [
"drive"
],
"parents": [
"1KJ4fvXcKVMGJunsKvPYf8PkX5K9SVwFk"
],
"starred": false,
"trashed": false,
"version": "3",
"iconLink": "https://drive-thirdparty.googleusercontent.com/16/type/application/pdf",
"mimeType": "application/pdf",
"ownedByMe": true,
"viewedByMe": true,
"createdTime": "2025-05-27T08:17:54.309Z",
"md5Checksum": "c1bda6d4249306eeb6b30da641eb2ad8",
"permissions": [
{
"id": "06783842879122931240",
"kind": "drive#permission",
"role": "owner",
"type": "user",
"deleted": false,
"photoLink": "https://lh3.googleusercontent.com/a/ACg8ocKYEvqVbfrYpVM3Esbt8CDt_Fije42MxkdcBFDBR1qni7Tgw5j7=s64",
"displayName": "Billy Christi Hartanto",
"emailAddress": "billychartanto@gmail.com",
"pendingOwner": false
}
],
"webViewLink": "https://drive.google.com/file/d/168eK7xkg9bhZRC9Nn3aoVbeU--Cy_4ie/view?usp=drivesdk",
"capabilities": {
"canCopy": true,
"canEdit": true,
"canShare": true,
"canTrash": true,
"canDelete": true,
"canRename": true,
"canComment": true,
"canUntrash": true,
"canDownload": true,
"canReadLabels": false,
"canAddChildren": false,
"canListChildren": false,
"canModifyLabels": false,
"canModifyContent": true,
"canReadRevisions": true,
"canRemoveChildren": false,
"canAcceptOwnership": false,
"canAddMyDriveParent": false,
"canMoveItemOutOfDrive": true,
"canMoveItemWithinDrive": true,
"canRemoveMyDriveParent": true,
"canMoveItemIntoTeamDrive": true,
"canMoveChildrenWithinDrive": false,
"canModifyContentRestriction": true,
"canRemoveContentRestriction": false,
"canEnableInheritedPermissions": true,
"canChangeSecurityUpdateEnabled": false,
"canChangeViewersCanCopyContent": true,
"canDisableInheritedPermissions": false,
"canModifyOwnerContentRestriction": true,
"canModifyEditorContentRestriction": true,
"canChangeCopyRequiresWriterPermission": true
},
"hasThumbnail": true,
"modifiedByMe": true,
"modifiedTime": "2025-05-27T08:17:38.000Z",
"sha1Checksum": "54243509f843e8ec9f2913715d9ae0f6df14cdde",
"fileExtension": "pdf",
"permissionIds": [
"06783842879122931240"
],
"thumbnailLink": "https://lh3.googleusercontent.com/drive-storage/AJQWtBNR_JHmbwFJT9hZOqNB1DU8CkWed-A0mH2ukYEDpQt7OdutXoLStFjhGHdTvgpzX3ORUOqOVaAeNqt9vuUJt0KUQ_0L0nxkCqXPZ68ybuhugn0=s220",
"headRevisionId": "0B3oBzhOa0rqUUCtZU3E5TDBGaUkrTEhETWNKQ1h0L2djcFRZPQ",
"quotaBytesUsed": "43627",
"sha256Checksum": "c2de358a0974f9b047aed8e457def7d4b1b39170f44819ec3152b42db787d72e",
"viewedByMeTime": "2025-05-27T08:17:54.309Z",
"webContentLink": "https://drive.google.com/uc?id=168eK7xkg9bhZRC9Nn3aoVbeU--Cy_4ie&export=download",
"isAppAuthorized": false,
"writersCanShare": true,
"modifiedByMeTime": "2025-05-27T08:17:38.000Z",
"originalFilename": "invoice123123.pdf",
"thumbnailVersion": "1",
"explicitlyTrashed": false,
"fullFileExtension": "pdf",
"lastModifyingUser": {
"me": true,
"kind": "drive#user",
"photoLink": "https://lh3.googleusercontent.com/a/ACg8ocKYEvqVbfrYpVM3Esbt8CDt_Fije42MxkdcBFDBR1qni7Tgw5j7=s64",
"displayName": "Billy Christi Hartanto",
"emailAddress": "billychartanto@gmail.com",
"permissionId": "06783842879122931240"
},
"linkShareMetadata": {
"securityUpdateEnabled": true,
"securityUpdateEligible": false
},
"viewersCanCopyContent": true,
"copyRequiresWriterPermission": false,
"inheritedPermissionsDisabled": false
}
]
},
"connections": {
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Invoice Parser AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"PDF Text Extractor": {
"main": [
[
{
"node": "Invoice Parser AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Download Invoice PDF": {
"main": [
[
{
"node": "PDF Text Extractor",
"type": "main",
"index": 0
}
]
]
},
"Invoice Folder Monitor": {
"main": [
[
{
"node": "Download Invoice PDF",
"type": "main",
"index": 0
}
]
]
},
"Invoice Parser AI Agent": {
"main": [
[
{
"node": "Insert Invoice Data",
"type": "main",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "Invoice Parser AI Agent",
"type": "ai_outputParser",
"index": 0
}
]
]
}
}
}如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 财务, 人工智能
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
Billy Christi
@billyI'm a professional software engineer and n8n expert with a passion for building scalable, no-code and low-code automation workflows. I specialize in creating seamless integrations between APIs, CRMs, and everyday tools to help businesses save time, reduce manual work, and operate smarter. Whether it's automating marketing pipelines, backend systems, or approval processes, I turn complex logic into simple, powerful workflows with n8n.
分享此工作流