Prompt
How do I use OCR to process invoices and receipts?
Latest observation
To use OCR for invoices and receipts, you usually build a pipeline like this:
1) Collect the document
Get the invoice/receipt as:
- scanned PDF
- photo from phone
- email attachment
- image file (JPG/PNG/TIFF)
2) Preprocess the image
Improve OCR accuracy before reading text:
- straighten/deskew
- crop borders
- increase contrast
- denoise
- sharpen
- convert to grayscale
- fix rotation
- split multi-page PDFs into pages
This matters a lot for receipts because they’re often blurry, crumpled, or photographed at an angle.
3) Run OCR
Use an OCR engine or service to extract text.
Common options:
- Tesseract — free, good for basic OCR
- Google Cloud Vision / Document AI
- AWS Textract
- Azure Form Recognizer / Document Intelligence
- ABBYY
- EasyOCR, PaddleOCR for open-source alternatives
For invoices/receipts, document-specific services often work better than plain OCR because they can detect fields like:
- vendor name
- invoice number
- date
- subtotal
- tax
- total
- line items
4) Extract structured fields
OCR gives you text, but you still need to identify fields.
Typical invoice/receipt fields:
- vendor/merchant
- address
- invoice/receipt number
- date
- due date
- line items
- quantity
- unit price
- subtotal
- tax
- tips
- total
- payment method
You can extract these using:
- regex rules
- keyword matching
- ML/AI document parsers
- template-based parsing if formats are consistent
5) Validate the results
OCR makes mistakes, so add checks:
- total = subtotal + tax + fees
- date is valid
- currency is recognized
- invoice number format matches expected pattern
- confidence thresholds for low-quality fields
Low-confidence fields can be sent to manual review.
6) Store the output
Save both:
- the original file
- extracted structured data in JSON, CSV, or a database
Example JSON:
{
"vendor": "Acme Supplies",
"date": "2026-10-11",
"invoice_number": "INV-10482",
"subtotal": 120.00,
"tax": 9.60,
"total": 129.60
}
7) Human review for exceptions
You’ll usually need a review step for:
- blurry photos
- handwritten notes
- unusual layouts
- foreign currencies
- multi-page invoices
- split bills or missing totals
Example workflow
If you want a practical system:
- Upload receipt image
- Preprocess it
- OCR the image
- Parse the text into fields
- Check totals and dates
- Save to accounting system or database
- Flag uncertain items for review
If you want to build it yourself
A simple Python stack might be:
- OpenCV for preprocessing
- Tesseract or PaddleOCR for OCR
- spaCy / regex for field extraction
- pandas / JSON for output
Minimal Python example with Tesseract
import pytesseract
from PIL import Image
image = Image.open("receipt.jpg")
text = pytesseract.image_to_string(image)
print(text)
Best practices
- Use document-specific OCR for invoices/receipts if possible
- Capture images with good lighting and flat angles
- Preserve original files for audit purposes
- Use confidence scores and manual review
- Handle different layouts and vendors
- Support PDFs and images
- Consider data privacy and compliance
If you want, I can also show you:
- a Python example for invoice OCR,
- a complete pipeline architecture, or
- recommendations for the best OCR tool depending on your budget and volume.