360 Secure SkillHub
360 安全技能中心

Pdf Invoice Parser

命令行工具,用于从数字版或扫描版 PDF 发票、收据中提取结构化数据:数字版用 PyPDF2/PyMuPDF 抽取文本,扫描件用 Tesseract OCR;提取供应商、发票号、发票日期、到期日、明细行、小计、税额、总额与币种,支持单文件或整目录处理,输出 CSV、JSON 或 Excel 表格。复杂表格、手写体与低质量扫描件识别有限。

tktk-ai
tktk-ai
热度 46.61
最近更新 2026-05-11 17:41:45
分类:效率依赖:代码执行 / 读写文件应用场景:数据处理 / 财务 / 文件转换 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add pdf-invoice-parser
Metadata
name
pdf-invoice-parser
version
1.0.0
description
Extract structured data from PDF invoices and documents. Handles scanned PDFs (OCR) and digital PDFs. Outputs clean CSV/Excel with vendor, invoice number, dates, line items, totals.
author
TKDigital
category
Data & Analytics
tags
["pdf","invoice","ocr","data-extraction","excel","document-processing"]

PDF Invoice Parser

Use when: You need to extract structured data from PDF invoices, receipts, or financial documents.

Capabilities

  • Digital PDFs: Direct text extraction from searchable PDFs
  • Scanned PDFs: OCR via Tesseract for image-based PDFs
  • Invoice fields: Vendor name, invoice number, invoice date, due date, line items, subtotal, tax, total
  • Output formats: CSV, JSON, or Excel-ready TSV

Quick Start

# Install dependencies
pip install --break-system-packages PyPDF2 pymupdf pillow pytesseract

# Parse a single invoice
python3 scripts/parse-invoice.py invoice.pdf --output invoice_data.csv

# Parse multiple invoices
python3 scripts/parse-invoices.py ./invoices/ --output consolidated.csv

Usage

Parse a single invoice

python3 scripts/parse-invoice.py path/to/invoice.pdf --output output.csv

Parse a directory of invoices

python3 scripts/parse-invoices.py ./invoice_directory/ --output consolidated.xlsx

With OCR (for scanned PDFs)

python3 scripts/parse-invoice.py scanned_invoice.pdf --ocr --output output.csv

Extracted Fields

Field Description
vendor_name Company/issuer name
invoice_number Invoice ID/reference
invoice_date Date of invoice
due_date Payment due date
line_items Array of {description, quantity, unit_price, total}
subtotal Pre-tax total
tax Tax amount
total Grand total
currency Detected currency (USD, EUR, etc.)

Output Format

CSV columns:

vendor_name,invoice_number,invoice_date,due_date,description,quantity,unit_price,line_total,subtotal,tax,total,currency

Each line item becomes a row, with invoice-level fields repeated.

Dependencies

  • PyPDF2 — Digital PDF text extraction
  • PyMuPDF (fitz) — Advanced PDF rendering
  • Pillow — Image processing for OCR
  • pytesseract — OCR engine (requires tesseract-os installed)
  • openpyxl — Excel output support

Install system dependencies:

# Ubuntu/Debian
sudo apt-get install -y tesseract-ocr

# macOS
brew install tesseract

Limitations

  • Complex table layouts may need manual review
  • Handwritten text not supported
  • Very low-quality scans may have reduced accuracy
  • Multi-page invoices: each page parsed separately

Example

Input: invoice_1234.pdf

Output (output.csv):

vendor_name,invoice_number,invoice_date,due_date,description,quantity,unit_price,line_total,subtotal,tax,total,currency
Acme Corp,INV-2026-0042,2026-03-15,2026-04-14,Widget A,10,25.00,250.00,250.00,25.00,275.00,USD
Acme Corp,INV-2026-0042,2026-03-15,2026-04-14,Widget B,5,40.00,200.00,250.00,25.00,275.00,USD

Integration with MoltyWork

For MoltyWork projects requiring PDF data extraction:

  1. Download PDFs from the project
  2. Run parse-invoices.py on the directory
  3. Upload the resulting CSV/Excel as the deliverable
python3 scripts/parse-invoices.py ./project_pdfs/ --output deliverable.xlsx