Stop Copy-Pasting Invoices: Extract PDF Data to CSV with 100 Lines of Python
Description and use
A 100‑line Python script extracts invoice_number, invoice_date, and total_amount from text‑based PDFs, writes a CSV, and flags missing data, cutting manual copy‑paste work.
Problem
Finance teams manually copy invoice data from PDFs into spreadsheets, a slow, error‑prone process.
Outcome
The 100‑line Python script extracts three key fields from text‑based invoices, writes them to CSV, and flags missing data, enabling quick review and reducing manual copy‑paste errors.
Workflow
- 1. Use pdfplumber to extract text from each PDF.
- 2. Apply anchored regexes to capture invoice_number, invoice_date, and total_amount.
- 3. Normalize amounts and write a CSV row, leaving fields empty if missing and adding a status note.
- 4. Batch process all PDFs in a folder, outputting a CSV and per‑file status.
- 5. Run a smoke test comparing results to an expected CSV generated from synthetic invoices.
Evidence
Every month, somebody on every finance team does the same soul-crushing job: open an invoice PDF, copy the invoice number into a spreadsheet, copy the date, copy the total, repeat forty times.
We'll use pdfplumber, which wraps pdfminer and gives you clean page text
Amounts get a light normalization (1,100.00 → 1100.00) so the CSV is spreadsheet- and diff-friendly.
The demo extracts three hardcoded fields from well-behaved PDFs. Real invoice work is messier, and three problems show up immediately: ...
- Record date: 2026-10-26T15:26:26.810Z