You have a PDF invoice. You need the data inside it — vendor name, invoice number, total, line items — in a format your code can use. Here's a direct path from PDF to structured data.
The Two Approaches (and Why One Is Better)
Approach 1 — Build it yourself: Use pdfplumber, PyMuPDF, or Camelot to extract raw text, then write regex patterns to find the invoice number, dates, and totals. Handle the edge cases when the text extraction fails on scanned PDFs. Write different patterns for different vendor formats. Maintain all of it when vendors update their invoice templates.
This takes 1–3 weeks for a working version, and it never fully works — there's always another vendor format that breaks it.
Approach 2 — Use an API: Send the PDF to an endpoint. Receive structured JSON. Done.
This guide covers Approach 2.
import pdfplumber import re # regex for every vendor format # breaks when template changes # no scanned PDF support # 300+ lines of brittle code
# POST /api/v1/extract, then
# GET /api/v1/documents/{id}
data = parse_document("invoice.pdf")
# merchant, total, tax, date
# line_items — all readyThe build-vs-buy decision for invoice parsing.
The Request
# 1. Submit the document
curl -X POST https://docuparseapi.com/api/v1/extract \
-H "Authorization: Bearer $DOCUPARSE_API_KEY" \
-F "file=@invoice.pdf"
# → {"success": true, "document_id": "<id>", "status": "queued"}
# 2. Fetch the result (repeat until "status" is "completed" or "failed")
curl https://docuparseapi.com/api/v1/documents/<id> \
-H "Authorization: Bearer $DOCUPARSE_API_KEY"That's the complete integration. Once the status is completed, the document's data object looks like this (a real 7-line-item invoice):
Python Implementation
Get your API key when you sign up at docuparseapi.com — free, no credit card.
Output:
Working With the Extracted Data
Map to a database model
Push to QuickBooks or Xero
The extracted fields map directly to the bill/invoice fields in accounting APIs:
Send to a webhook or downstream service
Handling Scanned PDFs
If the invoice was created by scanning a paper document, the PDF contains an image, not machine-readable text. Regular PDF parsers return nothing from these files. DocuParse API detects scanned PDFs automatically and applies OCR — your request is identical:
# Works for both digital PDFs and scanned PDFs
invoice = parse_document("scanned_supplier_invoice.pdf")Common Issues and Fixes
Issue: EXTRACTION_FAILED error
The document may be too degraded to extract cleanly (heavy compression, very low scan resolution, or a non-invoice document). Try with a higher quality scan, or submit a digital PDF if available.
Issue: Missing fields return null
Some invoices don't have due dates; some don't have line items. Check for None before using a field:
due_date = invoice.get("due_date") # May be None
if due_date:
# use itIssue: Total is a string, not a number The API returns monetary values as strings to preserve decimal precision. Convert before arithmetic:
total = float(invoice["total"])
Issue: Line items list is empty
Not all invoices have extractable line items — some use image-embedded tables or unusual formats. The total field is always extracted when possible, even if line items are missing.
Pricing
- Free tier: 20 PDF invoices/month, no credit card required
- Starter and Pro: monthly plans for higher volumes — see the Starter plan and the Pro plan on current pricing
- Billed per document, with up to 10 pages in each; 11–20 pages count as two