October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Extract Invoice Data from PDFs with Python and Validate It

A practical Python workflow for extracting invoice fields from text and scanned PDFs, parsing line items, and checking results before they reach accounting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Python to extract text from each invoice PDF, route image-based pages through OCR, map the results into a consistent record, and validate the fields and totals before using them. These are separate steps: PDF text extraction does not identify invoice meaning, and readable output is not necessarily correct output.

1. Check whether each page has extractable text

Start by opening the PDF and inspecting its pages. Digitally generated PDFs often contain text that a library can extract directly; scanned pages may contain only images and need optical character recognition (OCR). A PDF can also mix text and images, so assess pages rather than assuming the whole file follows one route. PyMuPDF documents page text extraction and OCR text pages in its basics guide.

This PyMuPDF example prints native text when present and otherwise tries OCR:

import pymupdf

with pymupdf.open("invoice.pdf") as doc:
    for page_number, page in enumerate(doc, start=1):
        text = page.get_text()
        if text.strip():
            print(page_number, text)
        else:
            ocr_page = page.get_textpage_ocr()
            print(page_number, page.get_text(textpage=ocr_page))

Treat this as a starting pattern, not a reliable classifier for every PDF. Check the output on your actual files. PyMuPDF’s OCR route depends on Tesseract language data, so install the data for the language used on your invoices; the PyMuPDF FAQ describes this requirement. OCR can misread identifiers, decimal points, and totals, so mark OCR-derived values for closer review.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Epson Workforce ES-50 Compact & Lightweight Mobile Document Scanner
  • PORTABLE SCANNER FOR USE ON-THE-GO — The fastest and lightest mobile single-sheet-fed compact document scanner in its class¹
  • QUICK DOCUMENT SCANNING ― This Epson ultra-fast scanner scans a single page as quickly as 5.5 seconds²; Windows and Mac compatible
  • VERSATILE PAPER HANDLING ― Portable scanner scans documents up to 8.5 x 72 in; Also easily digitizes receipts and ID cards to make accounting, bookkeeping, and organizing simpler
  • INTUITIVE, HIGH-SPEED SOFTWARE — Epson ScanSmart Software³ is a smart tool allowing you to easily scan, review, and save; Stay organized easily with the help of this Epson scanner
  • EASY SETUP — USB-powered connect to your computer for quick and simple scanning; No batteries or external power supply required to operate portable document scanner; Standard Connectivity: USB 2.0

2. Map extracted content into invoice fields

PDF extraction returns text or layout information, not an invoice record with fields such as vendor, invoice number, date, and total. Reading order can be awkward, and labels, values, and columns may be interleaved. Preserve the raw text and its file and page context, then apply parsing rules suited to the documents you receive.

A stable record shape makes downstream validation and review easier:

Rank #2
Sale
Brother DS-640 Compact Mobile Document Scanner, (Model: DS640)
  • FAST SPEEDS - Scans color and black and white documents a blazing speed up to 16ppm (1). Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • ULTRA COMPACT – At less than 1 foot in length and only about 1. 5lbs in weight you can fit this device virtually anywhere (a bag, a purse, even a pocket).
  • READY WHENEVER YOU ARE – The DS-640 mobile scanner is powered via an included micro USB 3. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan.
  • WORKS YOUR WAY – Use the Brother free iPrint&Scan desktop app for scanning to multiple “Scan-to” destinations like PC, Network, cloud services, Email and OCR. (2) Supports Windows, Mac and Linux and TWAIN/WIA for PC/ICA for Mac/SANE drivers. (3)
  • OPTIMIZE IMAGES AND TEXT – Automatic color detection/adjustment, image rotation (PC only), bleed through prevention/background removal, text enhancement, color drop to enhance scans. Software suite includes document management and OCR software. (4)
record = {
    "vendor_name": None,
    "invoice_number": None,
    "invoice_date": None,
    "currency": None,
    "line_items": [],
    "subtotal": None,
    "tax": None,
    "total": None,
    "source_file": "invoice.pdf",
    "source_pages": [],
}

For clean, machine-readable invoices, begin with explicit label-based parsing rules. Do not assume one regular expression will work across suppliers: labels, date formats, currencies, and layouts differ. Keep the original extracted text alongside parsed candidates so a reviewer can compare them.

Extract line-item tables according to their layout

For tables, PyMuPDF provides page.find_tables(). Its table detection depends on how the PDF draws the table: the PyMuPDF FAQ explains that it detects tables using vector graphics such as lines and rectangles. Borderless tables may not be detected as expected and can require text-based strategies or custom spatial logic. Inspect detected cells rather than assuming a successful call means the rows and columns are right.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Epson Workforce ES-400 II High-Speed Color Duplex Desktop Document Scanner
  • FAST DOCUMENT SCANNING — Document scanner with feeder allows you to speed through stacks with a 50-sheet Auto Document Feeder (ADF); Efficient office scanner to help you scan more productively
  • INTUITIVE, HIGH-SPEED SOFTWARE — Quickly scan with this desktop document scanner; Epson ScanSmart Software lets you easily preview scans, email files, upload to the cloud, and more; Plus, automatic file naming saves even more time
  • SEAMLESS INTEGRATION — Easily incorporate your data into most document management software with the included TWAIN driver; Office document scanner integrates seamlessly with business workflows
  • EASY SHARING — Duplex scanner allows you to scan straight to email or popular cloud storage2 services like Dropbox, Evernote, Google Drive, and OneDrive for simple storage and sharing
  • SIMPLE FILE MANAGEMENT — Scanner allows the creation of searchable PDFs with Optical Character Recognition (OCR) and convert scans to editable Word or Excel files effortlessly; Designed for home and office document scanning

For detailed layout inspection and visual debugging, pdfplumber exposes page objects such as characters, lines, and rectangles, as well as text and table extraction. It still requires document-specific parsing and checks.

3. Normalize dates and amounts before checking them

Convert parsed dates to a consistent representation and amounts to decimal values rather than binary floating-point values. Keep currency codes and locale assumptions explicit: a comma or period may have different meanings in different invoice conventions. These steps make comparisons more predictable, but they do not establish jurisdiction-specific tax or accounting rules; the technical sources cited here do not provide such guidance.

Rank #4
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
  • Scanner type: Document
  • Connectivity technology: USB
  • With Auto Scan Mode, the scanner automatically detects what you're scanning
  • Digitize documents and images
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

4. Validate fields and arithmetic, then review exceptions

Validation should be a separate stage. Define checks that fit the fields actually present on each invoice, and report failures rather than silently changing extracted values.

  • Check that required identifiers and dates are present and that dates parse under the document’s expected format.
  • Confirm that vendor and invoice number candidates come from invoice content rather than unrelated footer text or a purchase-order number.
  • Where quantity and unit price are provided, compare their product with the line amount using an explicit rounding tolerance.
  • Where the invoice presents comparable figures on the same basis, check whether the subtotal agrees with the sum of line amounts.
  • Reconcile subtotal, tax, other charges, discounts, and the printed total while accounting for the invoice’s stated rounding and calculation order.
  • Check whether currency and decimal separators are plausible for the document’s locale.
  • Flag possible duplicate invoice keys for review; do not automatically discard them.

When a check fails, keep the extracted candidate, the failed rule, and the source page together. For review, retain or produce a rendered page image so someone can compare the candidate with the original. PyMuPDF documents page rendering as well as text and OCR methods in its basics guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
ScanSnap iX2500 Wireless or USB High-Speed Document Scanner, Black
  • OUR MOST ADVANCED SCANSNAP. Large touchscreen, fast 45ppm double-sided scanning, 100-sheet document feeder, Wi-Fi and USB connectivity, automatic optimizations, and support for cloud services. Upgraded replacement for the discontinued iX1600
  • CUSTOMIZABLE. SHARABLE. Select personalized profiles from the touchscreen. Send to PC, Mac, mobile devices, and clouds. QUICK MENU lets you quickly scan-drag-drop to your favorite computer apps
  • STABLE WIRELESS OR USB CONNECTION. Built-in Wi-Fi 6 for the fastest and most secure scanning. Connect to smart devices or cloud services without a computer. USB-C connection also available
  • PHOTO AND DOCUMENT ORGANIZATION MADE EFFORTLESS. Easily manage, edit, and use scanned data from documents, receipts, photos, and business cards. Automatically optimize, name, and sort files
  • AVOIDS PAPER JAMS AND DAMAGE. Features a brake roller system to feed paper smoothly, a multi-feed sensor that detects pages stuck together, and skew detection to prevent paper damage and data loss

5. Choose a library by the PDFs you receive

Need Starting point Consideration
Text extraction, page rendering, OCR, and table finding through one API PyMuPDF Table detection depends on how the table is constructed; OCR requires Tesseract language data. See the basics guide and FAQ.
Inspecting page characters and layout objects or debugging a difficult page pdfplumber Layout-aware extraction still needs document-specific parsing and validation. See the pdfplumber project.
Image-based scanned pages PyMuPDF OCR with Tesseract, or another OCR stack tested on the language and scan quality OCR recognizes text; it does not verify that a value is the invoice number, tax, or total.

Evaluate candidates using representative invoices from your own suppliers. Compare native-text quality, table row and column fidelity, OCR behavior across languages and scan quality, coordinate preservation, runtime for your expected volume, and the effort needed to resolve exceptions. The cited project documentation describes capabilities, not a comparative invoice-accuracy benchmark; it does not establish a universal best library or an accuracy percentage.

Quick Recap

Bestseller No. 4
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Scanner type: Document; Connectivity technology: USB; With Auto Scan Mode, the scanner automatically detects what you're scanning
$75.00

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.