How to add document OCR to TOTVS Protheus
Short answer
Scan or receive documents, run layout-aware OCR on your own server, extract fields with a confidence score per field, match them to Protheus masters and orders, and write drafts through ExecAuto. Fiscal XML needs no OCR; the value is in the paper and PDF that still arrives alongside it.
Brazilian fiscal rules mean many Protheus plants already receive structured XML for invoices. OCR matters for what the XML does not cover: foreign supplier invoices, import documents, packing lists, certificates of analysis, delivery receipts signed by drivers, and scanned legacy paperwork.
Those documents still have to land on a record in Protheus, where the receiving clerk or the quality inspector would otherwise retype or simply file a paper copy.
A sound OCR setup does three things: reads accurately, shows how sure it is, and writes nothing into the ledger without the same checks a human entry would get.
What teams use it for
Import invoices and packing lists
Foreign supplier invoices and packing lists are read for item, quantity, origin and value, and drafted as inputs to the import process for the comex team to complete.
Certificates of analysis and test reports
Lot numbers, specification values and pass or fail are extracted and attached to the receiving lot in inventory control, so quality sees them at inspection.
Signed delivery receipts
Photos of signed canhotos or delivery receipts are read for invoice number and date, and used to close delivery tracking for the sales invoice.
Service and freight invoices
Non-stock invoices for freight, maintenance or services are coded to cost centers and accounts using supplier history, then queued for AP approval.
Legacy paper archive indexing
Scanned contracts and drawings are classified and indexed by document type and party so they can be linked to supplier and customer records.
TOTVS Protheus integration surface
- ExecAuto routines for pre-invoice and invoice entry and accounts payable titles, which apply validation when OCR output is posted as a draft.
- Protheus REST services for master lookups: suppliers, products with supplier cross-reference, open purchase orders and cost centers.
- The document attachment feature (banco de conhecimento) in Protheus for linking the scanned image or PDF to a record, with structure varying by release.
- TOTVS Fluig document management and GED where installed, which exposes a REST API for storing and classifying files and routing them to workflows.
- Lot and quality tables used for certificates, accessed through the standard quality routines or custom REST, not by direct inserts.
How it works
- 1
Define document types and target records
List each document type, the Protheus record it feeds and the fields needed. Start with one or two types; a general reader that handles all of them poorly is a common trap.
- 2
Capture and pre-process
Receive files from a watched folder, scanners, email or a mobile photo. Deskew, denoise and split multi-page files, and detect document type before extraction.
- 3
Extract with confidence
Use a layout-aware OCR and a vision or language model to produce fields with confidence per field, keeping the image region each value came from.
- 4
Validate against Protheus data
Check supplier exists, items map to products, totals add up, and the order is open. Failures reduce confidence and route to review.
- 5
Review screen for low confidence
Show the image beside the fields, highlight uncertain ones, and let a clerk correct and approve. Corrections feed a list of supplier-specific hints.
- 6
Post as a draft and attach the file
Create the entry through ExecAuto or custom routine and attach the original so audit sees both.
Example flows
Certificate of analysis at receiving
Trigger: A PDF certificate arrives with a chemical lot.
- OCR extracts lot number, product code, test values and result.
- Service finds the receiving lot and compares values to the specification.
- In-spec certificates are attached to the lot automatically.
- Out-of-spec values create a quality alert for the inspector.
Result: Quality sees the evidence with the lot at the moment of inspection, and deviations are flagged on receipt.
Freight invoice coding
Trigger: A scanned freight invoice is dropped in the AP folder.
- OCR reads supplier, document number, date, amount and tax lines.
- Service suggests cost center and account from the supplier's past entries.
- AP clerk confirms or edits in the review screen.
- A payable title is drafted and the file is attached.
Result: Typing is replaced by a quick confirmation, and coding becomes more consistent across clerks.
Keeping data on-prem
Document images are among the most sensitive data a plant holds: prices, tax ids, drawings, and sometimes controlled technical data. OCR and extraction can run entirely on-prem with open-source OCR engines and open-weight vision-language models on local GPUs, so no scan leaves the network. Connect the pipeline to the AppServer over internal REST and keep the review screen inside the corporate network or behind your VPN. A smaller model is often enough for clean, repeated supplier layouts, and you can reserve a larger one for odd documents. This also helps with export-controlled or customer-restricted drawings, where sending a file to an external cloud OCR service may breach your obligations.
Security checklist
- Store scans in an encrypted location with access limited by role, and apply the retention period your fiscal rules require.
- Never auto-post above a defined value or for new suppliers without a human check.
- Keep the image, extracted fields, model version and reviewer together in an audit record.
- Separate the OCR service account from Protheus users and give it draft-only routines.
Ways to get it done
Use Fluig or a TOTVS document capture offering if already licensed
Effort: Configuration plus workflow design.
Document storage and routing needs, with light extraction.
Build an in-house pipeline with open-source OCR
Effort: Six to ten weeks for the first type with review screen.
A few stable document types and a team comfortable running Python services.
Partner-built pipeline with on-prem vision models, such as Netray
Effort: Pilot on one document type, measure accuracy, then add types.
Many layouts, handwritten or low-quality scans, and data that cannot leave the plant.
Pitfalls
- !Measuring accuracy on clean samples only; test on the worst scans from the receiving dock.
- !Treating a total as correct without checking that lines sum to it.
- !Skipping the review screen to save time and discovering errors at month-end close.
- !Posting OCR output into stock or fiscal tables directly rather than drafts through the standard routines.
Frequently asked questions
Do I need OCR if I already get NF-e XML?
Not for those invoices, since the XML is structured and should be parsed directly. OCR helps with foreign invoices, packing lists, certificates, receipts and any paper documents that arrive without structured data.
How accurate is OCR on supplier invoices?
It depends on scan quality and layout variety. Clean, repeated layouts can reach high field-level accuracy, while poor scans need review. Use per-field confidence and measure on your own documents before setting auto-post thresholds.
Can OCR results be written straight into Protheus?
They should be written as drafts through ExecAuto or custom routines so validations run. Direct table inserts bypass business rules and fiscal checks and make later reconciliation painful.
Can it run without sending documents to the cloud?
Yes. Open-source OCR and open-weight vision-language models run on local GPUs, and the pipeline talks to Protheus over internal REST. Nothing needs to leave your network.
Where should the scanned files be stored?
Attach them to the Protheus record using its document feature, or store them in Fluig or a file share and link by key. Whichever you choose, keep access controls and fiscal retention rules aligned with the original paper.
Want Document OCR working on your TOTVS Protheus?
A free 30 minute assessment: we map the integration path for your version and setup, and where it should run.
Get a free assessment