# How to add document OCR to ERPNext

> Source: https://netray.co/integrations/erpnext-document-ocr
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Integrations

## Short answer

Attach each scanned document to ERPNext through the File DocType, run OCR and field extraction outside the transaction, and create draft Purchase Invoices, Purchase Receipts or attachments with confidence scores. Anything below your threshold goes to a person before it touches the ledger.

## System

ERPNext

## Capability

document-ocr

## Intro

ERPNext stores documents well but does not read them. Supplier invoices arrive as PDFs and photographs, packing slips as scans, and quality certificates as stamped pages. Accounts staff key header fields and lines into a Purchase Invoice, then attach the file so an auditor can find it later.

OCR changes the keying work, not the controls. The bar is not 'read the page', it is 'produce a draft that already matches a Purchase Order and Purchase Receipt, and tell me which fields to doubt'. That depends on how well the extraction is joined to ERPNext master data, much more than on the OCR engine you choose.

## Use Cases

### Supplier invoice to draft Purchase Invoice

**Description:** Extract supplier, invoice number, date, tax and line amounts, match the supplier by name or tax ID, and propose a Purchase Invoice linked to the matching Purchase Receipt.

### Packing slip to Purchase Receipt

**Description:** A scanned packing slip becomes a draft Purchase Receipt against the Purchase Order, with received quantities and batch or lot numbers filled in for the receiving clerk to confirm.

### Certificates of conformance and material certs

**Description:** Capture heat numbers and lot IDs from mill certificates and attach them to the Batch record, so traceability does not rely on a folder of PDFs.

### Expense Claim receipts

**Description:** Receipt photos from a phone feed an Expense Claim draft with date, vendor, amount and tax, ready for approval under the existing Workflow.

### Customer documents on Sales Orders

**Description:** Scanned customer drawings and signed POs are indexed against the Sales Order, with text made searchable for later questions.

## System Surface

- File DocType and the upload API: attach files to any document with attached_to_doctype and attached_to_name, public or private, stored in the site's private files folder or an S3-compatible backend if configured.
- Purchase Invoice, Purchase Receipt and Expense Claim DocTypes created as drafts through /api/resource, with docstatus 0 until submit.
- Item Supplier and Supplier fields (including tax ID) for matching, and Purchase Order Item for three-way matching against ordered and received quantities.
- Bank Statement Import and Data Import tools in the Desk for bulk-structured data, which are different from document capture but useful to know about.
- doc_events on File after_insert, plus RQ background jobs, to trigger extraction without slowing the upload.

## How It Works

### Define document types and landing places

**Detail:** Decide which documents you will capture first, usually supplier invoices. Give each a landing route, such as an upload page or an invoices@ mailbox, and a target DocType.

### Ingest through File

**Detail:** Create the File record with the document attached to a placeholder or a custom 'Document Intake' DocType. Keep the original untouched for audit.

### Extract with OCR and a layout-aware model

**Detail:** Use OCR for scans and read text directly from digital PDFs. Pull header fields and lines with per-field confidence, preferring tools that handle tables and multiple languages.

### Validate against ERPNext

**Detail:** Check the supplier exists, the PO number is open, quantities do not exceed the receipt, currency matches, and tax totals reconcile. Fail loudly rather than patching numbers.

### Create a draft and flag low confidence

**Detail:** Insert the draft document, highlight uncertain fields in a Comment or a custom status, and assign it to accounts through ToDo.

### Review, correct, learn

**Detail:** Record what reviewers change. Frequent corrections on a supplier become a template or mapping rule, which raises straight-through rates over time.

## Example Flows

### Invoice against a received PO

**Trigger:** PDF invoice lands in the invoices mailbox and is attached as a File.

**Steps:**

- Extraction yields supplier, number, date, three lines and a total with confidence scores.
- Validation finds an open PO and matching receipt; line prices differ by two percent on one line.
- A draft Purchase Invoice is created, with the price variance noted.
- Accounts accepts the variance or contacts the supplier, then submits.

**Result:** Three-way match is largely done before a person opens the invoice, and exceptions are visible.

### Mill cert to Batch

**Trigger:** Scanned certificate is uploaded against a Purchase Receipt.

**Steps:**

- OCR extracts heat number, specification and quantity.
- A match is attempted to the Batch created on receipt.
- The File is attached to the Batch and the heat number is added to a custom field after confirmation.

**Result:** Traceability queries find the certificate by heat or lot number in seconds.

## On Prem

OCR and extraction can run entirely inside your network. Open-source OCR engines and layout-aware open-weight models run on a modest GPU server, and ERPNext's private files never leave your storage. This matters for drawings, regulated customer documents and export-controlled data. Keep the extraction service on an internal address, call ERPNext only through its API with a scoped user, and store confidence scores and the original file together. Expect to evaluate accuracy on your own scans, since fax-quality pages, stamps and handwriting reduce results, and plan a review queue rather than assuming perfect reads.

## Security

- Store originals in private files and restrict File access by DocType permissions, not by obscure URLs.
- Never let extraction submit a document or release payment; drafts only until accuracy is proven.
- Reconcile extracted totals with line sums and tax, and alert on bank detail changes in invoices.
- Scan uploads for malware and limit file types and sizes.
- Keep audit evidence: original file, extracted values, reviewer and final values.

## Options

### Manual keying with ERPNext attachments

**Fit:** Low invoice volume where review time already fits the day.

**Effort:** None, but ongoing labor.

### Commercial OCR service or invoice-capture product through the API

**Fit:** Teams comfortable sending documents to a cloud processor and wanting speed to value.

**Effort:** One to three weeks to integrate and tune matching.

### Self-hosted OCR with a partner such as Netray

**Fit:** Sensitive documents, mixed languages, or customer-specific formats that need local control.

**Effort:** Pilot on one document type, then extend to receipts and certificates.

## Pitfalls

- Trusting header totals without checking line sums lets one misread digit reach the ledger.
- Matching suppliers by fuzzy name alone creates duplicates; use tax ID or bank details as a second signal.
- Not keeping the original file breaks audit; always attach the source.
- Multi-page invoices with continuation pages are commonly split wrongly; test them early.
- Tuning on clean samples overstates accuracy; use a random month of real documents.

## Faq

### Does ERPNext include OCR for invoices?

**Answer:** Not in the core product as far as I know. ERPNext stores files and has data import tools, but reading a scanned invoice into a Purchase Invoice is usually done with an external OCR service or a Frappe app, which creates drafts through the API.

### What confidence threshold should we use?

**Answer:** Start with human review of everything, then relax by supplier and field once measured accuracy is consistently high. Amounts, dates and PO numbers deserve stricter thresholds than descriptive text, and bank details should always be reviewed.

### Can OCR run without sending documents to the cloud?

**Answer:** Yes. Open-source OCR and open-weight document models can run on your own servers. Quality varies with scan quality and layout, so test them against your real documents before deciding.

### How do I connect extracted data to Purchase Orders?

**Answer:** Use the PO number if present, otherwise supplier plus item and quantity to find open Purchase Order Items. Present candidates instead of auto-selecting when more than one fits, and link the invoice items to the PO through the standard reference fields.

### What about handwritten documents?

**Answer:** Handwriting is much less reliable than print. Treat handwritten fields as suggestions, route them to review, and where possible replace the paper step with a mobile form so the data starts out structured.

## Search terms

erpnext ocr, erpnext invoice ocr, erpnext document scanning, erpnext purchase invoice from pdf, erpnext ai invoice processing, frappe ocr integration, erpnext supplier invoice capture, erpnext packing slip scanning, erpnext certificate of conformance, on prem ocr for erpnext

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
