Invoice Data Extraction: How to Get Invoice PDFs Into CSV or Excel Automatically
From a no-code converter for a few invoices to a Python script that reads a whole folder.

Invoice data extraction means pulling the invoice number, date, supplier, line items and totals out of PDF invoices into rows of a CSV file or an Excel sheet. For a handful of invoices, a PDF to Excel converter plus a few minutes of tidying does it; for a steady stream, a short Python script reads a whole folder for you.
Either way, scanned invoices need OCR first, because a scan holds a picture of the text and no text you can extract.
What Invoice Data Extraction Involves
Every method does the same three things. It gets the text out of the PDF, finds the fields you care about, and writes them into a table with one row per invoice (or one per line item).
How hard that is depends on the PDF:
- Digital invoices, saved straight from an accounting or billing program, have selectable text. This is the easy case.
- Scanned invoices are images. They need OCR (optical character recognition) to turn the picture back into text.
- Many different layouts from many suppliers make field-finding the hard part, since every vendor puts the total somewhere else.
Which Approach Fits Your Invoices
Few invoices, digital PDFs: use a converter and copy the fields into your own table. No code. For a quick look first, PDF Data Extraction lists every date, email address, phone number and money amount it finds.
A regular batch from a few suppliers: a Python script with one pattern per layout, as shown below.
Dozens of changing layouts: cloud document services such as Amazon Textract, Google's Document AI or Azure Document Intelligence in Foundry Tools. Textract's docs say it reads invoices with no templates, and Azure lists a prebuilt invoice model. They send your invoices to the provider, so check that's allowed for your data, and check the pricing.
Check for an Embedded XML File First
A ZUGFeRD or Factur-X invoice already holds its data, so you may not need to extract anything. The EU's country sheet for Germany describes ZUGFeRD as "a hybrid electronic invoice format that combines a PDF document with an embedded XML file", and the French forum behind Factur-X says the two are technically identical.
German businesses have had to be able to receive e-invoices since 1 January 2025, per the same EU sheet.
To look for the file, use Poppler's pdfdetach (sudo apt install poppler-utils on Debian or Ubuntu, brew install poppler on a Mac):
1pdfdetach -list invoice.pdf
2pdfdetach -save 1 -o invoice.xml invoice.pdfDo this before you merge. In November 2026 we attached a sample XML file to a test invoice and ran it through our pages in Chrome on a Mac: it was still there after Compress PDF, and gone after Merge PDF. To send several invoices as one file, PDF to ZIP packs them without changing a byte, so the attached XML stays.
Extract Invoice Data Without Code
- Open PDF to Excel and upload one invoice PDF (up to 25 MB).
- Click Convert to Excel and download the XLSX.
- Find the header block, the line items and the totals in the sheet.
- Copy the values you need into your own table and check the totals against the PDF.

The workbook has one sheet, PDF Text, with the text placed in columns by its position on the page. Every cell holds text, so turn amounts into numbers before you add them up. Our guide to converting a PDF invoice to Excel walks through the cleanup.
Got a pile of invoices with no XML inside? Combine them with Merge PDF and convert the merged file once. When we did that with three test invoices in October 2026, all of them landed in one workbook, in order.
Prefer plain rows? PDF to CSV keeps only the lines that look like table rows and writes them to a UTF-8 CSV. Our three-row test table came back as exactly three lines.

Scanned Invoices Need OCR First
Both converters stop with a message when a PDF has no selectable text. Run the scan through OCR PDF first: it adds an invisible text layer to every page, then convert the OCR copy.

Our OCR reads English only. For code, the same engine is free to run yourself: Tesseract is open source under the Apache 2.0 license.

Check every recognized digit. OCR mixes up look-alikes such as O and 0, and on an invoice that means a wrong amount. Our guide to extracting financial data from PDFs lists checks that catch it, like adding up each column against the printed totals.
Python Workflow: Invoice PDF to CSV
This script uses pdfplumber to read the text of digital PDFs and pandas to write the CSV.
Step 1: Install the Libraries
1pip install pdfplumber pandas
2Step 2: Extract Text From the PDF
1import pdfplumber
2
3def extract_text(pdf_path):
4 with pdfplumber.open(pdf_path) as pdf:
5 text = ""
6 for page in pdf.pages:
7 text += page.extract_text() or ""
8 return textpdfplumber opens each page and returns its embedded text. Its README says it works best on machine-generated PDFs, not scans, so an empty result is your cue to OCR the file first.
Step 3: Parse the Invoice Fields
1import re
2
3def parse_invoice_fields(text):
4 invoice_number = re.search(r"\bInvoice\s*(?:No\.?|Number)?\s*[:#]\s*(\S+)", text, re.IGNORECASE)
5 date = (re.search(r"\bInvoice\s+Date\s*[:#]\s*(\S+)", text, re.IGNORECASE)
6 or re.search(r"(?<!Due )\bDate\s*[:#]\s*(\S+)", text, re.IGNORECASE))
7 # Not "Subtotal", "Sub-Total" or "Sub Total", which come first on most invoices.
8 amount = re.search(r"(?<![\w-])(?<!Sub )Total\s*[:#]?\s*\$\s*([0-9,]+\.?\d*)", text, re.IGNORECASE)
9
10 return {
11 "invoice_number": invoice_number.group(1) if invoice_number else "",
12 "date": date.group(1) if date else "",
13 "amount": amount.group(1) if amount else ""
14 }The regular expressions look for labels like "Invoice #INV-0042" and "Date: 04/15/2025". Print the raw text of a few of your own invoices first and adjust the patterns to the labels your suppliers really use.
Does the Script Read Subtotal as the Total?
This guide's earlier pattern did, and the one above is the fix. A plain Total pattern also matches the end of "Subtotal", and the first match wins. We ran both versions on sample text in November 2026, including text pdftotext read from a generated invoice PDF:
| Invoice text | Old pattern read | Fixed pattern reads |
|---|---|---|
| Subtotal: $100.00, then Total: $108.00 | 100.00 | 108.00 |
| Sub-Total: $50.00, then Total: $54.00 | 50.00 | 54.00 |
| Sub Total: $20.00, then Total: $21.00 | 20.00 | 21.00 |
| Subtotal: $20.00, then Total Due: $21.00 | 20.00 | Nothing |
| Due Date: 05/15/2025, then Invoice Date: 04/15/2025 | 05/15/2025 | 04/15/2025 |
| Invoice Number: 48 | Nothing | 48 |
The empty result is the safe failure: "Total Due" isn't in the pattern, so add it if your suppliers use it, and let the validation below flag the rest. Amounts with no dollar sign (21.00 EUR) come back empty in both versions.
Step 4: Pull the Line Item Tables
1def extract_tables(pdf_path):
2 with pdfplumber.open(pdf_path) as pdf:
3 for page in pdf.pages:
4 tables = page.extract_tables()
5 for table in tables:
6 print(table)Line items usually sit in a table. pdfplumber returns each table as a list of rows, and each row as a list of cells.
Step 5: Save Everything to CSV
1import pandas as pd
2
3def save_to_csv(records, output_path):
4 df = pd.DataFrame(records)
5 df.to_csv(output_path, index=False)
6 print(f"Saved {len(records)} invoices to {output_path}")Pass it the list of parsed invoices and it writes one row per invoice.
Python Workflow: Invoice PDF to Excel
An Excel file can hold several sheets, so the raw rows and a summary fit in one workbook. Writing .xlsx needs the openpyxl package (pip install openpyxl), not Excel itself.
1import pandas as pd
2
3def save_to_excel(records, output_path):
4 df = pd.DataFrame(records)
5 if "amount" in df.columns:
6 df["amount"] = pd.to_numeric(df["amount"].str.replace(",", ""), errors="coerce")
7
8 # Main data sheet
9 with pd.ExcelWriter(output_path, engine="openpyxl") as writer:
10 df.to_excel(writer, sheet_name="Invoices", index=False)
11
12 # Summary sheet
13 summary = {
14 "Total Invoices": [len(df)],
15 "Total Amount": [df["amount"].sum() if "amount" in df.columns else 0],
16 "Average Amount": [df["amount"].mean() if "amount" in df.columns else 0]
17 }
18 summary_df = pd.DataFrame(summary)
19 summary_df.to_excel(writer, sheet_name="Summary", index=False)The summary values are written once, when the script runs. They're not live formulas. The parser returns amounts as text such as "1,250.00", so the function converts them to numbers first, and an empty amount stays empty.
Invoice Data Extraction Tools Compared
| Tool | Key Features | Best For |
|---|---|---|
| PDF to Excel and PDF to CSV on pdf-file.com | No code, free, one PDF per run. Text goes into cells by position; you pick out the fields yourself. | A few digital invoices |
| Amazon Textract | Amazon's document service. Its AnalyzeExpense operation returns invoice fields and line items. | Fully automated cloud pipelines |
| Rossum | AI agents that read and validate documents, with an accounts payable solution. | Accounts payable teams |
| Tabula | Free, open source tool for pulling tables out of PDFs. Text-based PDFs only, not scans. | Clean line-item tables |
| pdfplumber plus Tesseract | Free Python libraries; you write the parsing yourself. | Developers with steady layouts |
CSV vs Excel for Extracted Invoice Data
| Feature | CSV | Excel |
|---|---|---|
| File size | Tiny | Larger |
| Formula support | None | Full formula engine |
| Multiple sheets | No | Yes |
| Opens in any app | Yes | Needs Excel or compatible app |
| Best for | Large datasets | Reporting and review |
| Formatting preserved | No | Yes |
CSV is plain text with one record per line. Use it when the data goes on to another system, such as an accounting import.
Use Excel when a person reviews the results and wants formatting, filters and formulas. To hand the totals on as a formatted PDF, type them into our Report Generator.
Common Invoice Extraction Mistakes
Running Text Extraction on Scans
A scanned PDF gives the script no text to match, and it quietly writes empty rows. Route scans through OCR before the field parsing.
One Regex for Every Supplier
A pattern built for one layout misses on the next. Keep one pattern set per supplier, and flag any invoice where nothing matched for a person to check.
Ignoring Date Formats
04/15/2025 and 15.04.2025 are the same day. Parse dates explicitly and store them as YYYY-MM-DD so they sort correctly.
Storing Amounts as Text
"$1,250.00" stored as text won't add up in Excel. Strip the currency sign and thousands separators, then convert to a number.
Skipping Validation
An empty amount or a missing date usually means the extraction failed, not that the invoice is free. Check every record and flag the odd ones.
Process a Whole Folder of Invoices
1from pathlib import Path
2
3def process_folder(input_folder, output_csv):
4 records = []
5 pdf_files = Path(input_folder).glob("*.pdf")
6
7 for pdf_path in pdf_files:
8 text = extract_text(str(pdf_path))
9 fields = parse_invoice_fields(text)
10 fields["source_file"] = pdf_path.name
11 records.append(fields)
12
13 save_to_csv(records, output_csv)Save the functions above in one file, invoice_extractor.py, and end it with a call:
1process_folder("/path/to/invoices", "/path/to/invoices.csv")You get one CSV with a row per invoice and the file it came from.
On macOS or Linux, a cron job can run the script every morning at 8:00:
10 8 * * * /usr/bin/python3 /path/to/invoice_extractor.pyPut the path that which python3 prints in place of /usr/bin/python3, so the job finds the packages you installed.
On Windows, Task Scheduler does the same job.
Frequently Asked Questions about Invoice Data Extraction
What if my invoices are scanned images?
Run OCR first. OCR PDF on pdf-file.com does it for English invoices, and Tesseract does it in your own scripts.
Can I extract line items and totals separately?
Yes. pdfplumber's table extraction targets the line items, while totals usually sit below the table and need their own pattern.
Do I need Excel installed to save .xlsx files?
No. The openpyxl library writes Excel files on Windows, macOS and Linux without Microsoft Office.
Is there a free way to extract invoice data?
Yes. PDF to Excel and PDF to CSV are free for a few invoices, and pdfplumber plus Tesseract cost nothing for scripts. Similar cases, like bank statements for QuickBooks or insurance EOBs you post by hand, work the same way.


