How itvincent-git/invoice_renamer works
Project type and purpose
• This is a Python-based command-line utility (“Invoice Renamer”) that processes invoice files (PDF/JPG) using OCR to extract date & amount, then renames them into a standardized format and writes them to a ‘rename’ directory.
File structure
• Top-level files:
• main.py – CLI entry point
• paddle/ – contains an example/demo script (paddle-demo.py) showing how OCR is invoked
• pyproject.toml & uv.lock – dependency and environment specification
• README.md, LICENSE, .gitignore – docs and metadata
• No separate “frontend” or “backend” folders: this is a single-process tool.
README for additional insights
• Dependencies: paddleocr, pdf2image, argparse, Python ≥3.11
• Features: single-file or directory processing, Chinese invoice support
• Output: standardized filename YYYYMMDD_AMOUNT元.pdf in a ‘rename’ directory
Main components & their relationships
a. CLI / main.py
– Parses arguments (file or directory path) via argparse
– Invokes the Controller / Orchestrator
b. File Handler
– Walks directories, filters for PDF/JPG files
– For PDFs, delegates to PDF Converter
c. PDF Converter (pdf2image)
– Converts PDF pages into images for OCR
d. OCR Processor (PaddleOCR)
– Runs text recognition on images or JPGs
e. Data Extractor
– Parses OCR results to find invoice date & amount
f. Renamer Service
– Constructs new filename
– Writes/moves file into ‘rename’ directory
g. Demo Script (paddle/paddle-demo.py)
– Stand-alone example of OCR usage
Data flow:
[CLI/main.py] → [File Handler] → (PDF?), → [PDF Converter] → [OCR Processor] → [Data Extractor] → [Renamer Service] → [Output Directory]
Architectural patterns & design principles
• Single-process, modular pipeline
• Separation of concerns: I/O, conversion, OCR, parsing, renaming
• Dependency injection of OCR engine via a demo module
• Configured by pyproject.toml & uv.lock for reproducibility
• External libraries/frameworks at the periphery (pdf2image, PaddleOCR, argparse).