Invoice OCR Java
The java client library supports the invoice API for extracting data from invoices.
Using this sample invoice below,
we are going to illustrate how to extract the data that we want using the client library.
Quick Start
public class SimpleMindeeClient {
public static void main(String[] args) throws IOException {
// Init a new client
MindeeClient client = new MindeeClient("my-api-key");
// Load a file from disk and parse it
LocalInputSource localInputSource = new LocalInputSource(
new File("./a74eaa5-c8e283b-sample_invoice.jpeg")
);
PredictResponse<InvoiceV4> document = mindeeClient.parse(
InvoiceV4.class, localInputSource
);
// Print a summary of the parsed data
logger.info(document.toString());
}
}
Output:
########
Document
########
:Mindee ID: 656c2ec1-0920-4556-9bc2-772162bc698a
:Filename: invoice.pdf
Inference
#########
:Product: mindee/invoices v4.1
:Rotation applied: Yes
Prediction
==========
:Locale: fr; fr; EUR;
:Document type: INVOICE
:Invoice number: 0042004801351
:Reference numbers: AD29094
:Invoice date: 2020-02-17
:Invoice due date: 2020-02-17
:Supplier name: TURNPIKE DESIGNS CO.
:Supplier address: 156 University Ave, Toronto ON, Canada M5H 2H7
:Supplier company registrations: 501124705; FR33501124705
:Supplier payment details: FR7640254025476501124705368;
:Customer name: JIRO DOI
:Customer address: 1954 Bloon Street West Toronto, ON, M6P 3K9 Canada
:Customer company registrations: FR00000000000; 111222333
:Taxes: 97.98 20.00%
:Total net: 489.97
:Total taxes: 97.98
:Total amount: 587.95
:Line Items:
====================== ======== ========= ========== ================== ====================================
Code QTY Price Amount Tax (Rate) Description
====================== ======== ========= ========== ================== ====================================
4.31 (2.10%) PQ20 ETIQ ULTRA RESIS METAXXDC
1.00 65.00 75.00 10.00 Platinum web hosting package Down...
XXX81125600010 1.00 250.01 275.51 25.50 (10.20%) a long string describing the item
ABC456 200.30 8.101 1622.63 121.70 (7.50%) Liquid perfection
CARTOUCHE L NR BROTHER TN247BK
====================== ======== ========= ========== ================== ====================================
Page Predictions
================
Page 0
------
:Locale: fr; fr; EUR;
:Document type: INVOICE
:Invoice number: 0042004801351
:Reference numbers:
:Invoice date: 2020-02-17
:Invoice due date: 2020-02-17
:Supplier name:
:Supplier address:
:Supplier company registrations: 501124705; FR33501124705
:Supplier payment details: FR7640254025476501124705368;
:Customer name:
:Customer address:
:Customer company registrations:
:Taxes: 97.98 20.00%
:Total net: 489.97
:Total taxes: 97.98
:Total amount: 587.95
:Line Items:
====================== ======== ========= ========== ================== ====================================
Code QTY Price Amount Tax (Rate) Description
====================== ======== ========= ========== ================== ====================================
4.31 (2.10%) PQ20 ETIQ ULTRA RESIS METAXXDC
1.00 65.00 75.00 10.00 Platinum web hosting package Down...
====================== ======== ========= ========== ================== ====================================
Page 1
------
:Locale: fr; fr; EUR;
:Document type: INVOICE
:Invoice number:
:Reference numbers: AD29094
:Invoice date:
:Invoice due date: 2020-02-17
:Supplier name: TURNPIKE DESIGNS CO.
:Supplier address: 156 University Ave, Toronto ON, Canada M5H 2H7
:Supplier company registrations:
:Supplier payment details:
:Customer name: JIRO DOI
:Customer address: 1954 Bloon Street West Toronto, ON, M6P 3K9 Canada
:Customer company registrations:
:Taxes: 193.20 8.00%
:Total net:
:Total taxes: 193.20
:Total amount: 2608.20
:Line Items:
====================== ======== ========= ========== ================== ====================================
Code QTY Price Amount Tax (Rate) Description
====================== ======== ========= ========== ================== ====================================
XXX81125600010 1.00 250.00 250.00 (10.00%) a long string describing the item
ABC456 200.30 8.101 1622.63 121.70 (7.50%) Liquid perfection
CARTOUCHE L NR BROTHER TN247BK
====================== ======== ========= ========== ================== ====================================
Extracted Fields
Attributes that will be extracted from the document and available in the inference
object:
- Invoice Number
- Reference Numbers
- Locale
- Invoice Date
- Due Date
- Customer Name
- Customer Address
- Customer Company Registration
- Supplier name
- Supplier Address
- Supplier Company Registrations
- Payment Details
- Line items
- Taxes
- Total Tax
- Total Including Taxes
- Total Excluding Taxes
Invoice Information
Invoice Number
The invoice number for the invoice being processed
invoiceNumber
of type Field
logger.info(invoiceDocument.getInference().getDocumentPrediction().getInvoiceNumber()getValue());
Reference Numbers
The reference numbers for the invoice being processed
referenceNumbers
of list of type Field
logger.info(invoiceDocument.getInference().getDocumentPrediction().getReferenceNumbers()getValue();
Locale
locale
of type [Locale]((https://developers.mindee.com/docs/java-field#locale)
Invoice Date
- invoiceDate of type Date
Due Date
- dueDate of type Date
Customer Information
Customer Name
Customer's name
customerName
of type Field
logger.info(invoiceDocument.getInference().getCustomerName().getReference()getValue();
Customer Address
Customer's Postal Address
customerAddress
of type Field
logger.info(invoiceDocument.getInference().getDocumentPrediction().getCustomerAddress().getValue();
Customer Company Registration
A list with the customers company registration information
customerCompanyRegistrations
of type List< Field >
The field contains an extraField with a key "type"
invoiceDocument.getInference().getDocumentPrediction().getCustomerCompanyRegistrations().stream()
.map((registration) -> String.join(":",registration.getExtraFields().get("type"),
registration.getValue()))
.forEach(System.out::println);
Supplier Information
Supplier Name
supplierName
of type Field
logger.info(invoiceDocument.getInference().getDocumentPrediction().getSupplierName().getValue());
Supplier Address
- supplierAddress of type Field
logger.info(invoiceDocument.getInference().getDocumentPrediction().getSupplierAddress().getValue());
Supplier Company Registrations
A list with the supplier's company registration information
supplierCompanyRegistrations
of type List< CompanyRegistration >
The field contains an extraField with a key "type" - Type of company registration number among: VAT NUMBER, SIRET, SIREN, NIF, CF, UID, STNR, HRA/HRB, TIN (includes EIN, FEIN, SSN, ATIN, PTIN, ITIN), RFC, BTW, ABN, UEN, CVR, ORGNR, INN, DPH, GSTIN, COMPANY REGISTRATION NUMBER (UK), KVK, DIC
invoiceDocument.getInference().getDocumentPrediction().getCustomerCompanyRegistration().stream()
.map((registration) -> String.join(":",registration.getExtraFields().get("type"),
registration.getValue()))
.forEach(System.out::println);
/// SAMPLE OUTPUT
// VAT NUMBER:FR1112323222
// SIRET:1111111111
// SIREN:1122221111
Payment Details
A list of the invoice supplier's payment details.
supplierPaymentDetails
of type List< PaymentDetails >
invoiceDocument.getInference().getDocumentPrediction().getSupplierPaymentDetails()
.stream().map(PaymentDetails::getSupplierPaymentDetailsSummary)
.forEach(System.out::println);
Line items
LineItems
(List): Line items details.
Each object in the list contains the following getter methods:
getProductCode()
(String)geDescription()
(String)getQuantity()
(Double)getUnitPrice()
(Double)getTotalAmount()
(Double)getTaxRate()
(Double)getTaxAmount()
(Double)getConfidence()
(Double)getPageId()
(Double)getPolygon()
(Polygon)
Taxes and Amounts
Taxes
A list of the taxes seen on the invoice
taxes
of type List < Tax >
invoiceDocument.getInference().getDocumentPrediction().getTaxes()
.stream()
.map(Tax::getTaxSummary)
.forEach(System.out::println);
Total Tax
The total tax for the invoice
totalTax
of type Amount
logger.info(invoiceDocument.getInference().getDocumentPrediction().getTotalTax().getValue());
Total Amount
The total amount including taxes for the invoice
totalAmount
of type Amount
logger.info(invoiceDocument.getInference().getDocumentPrediction().getTotalAmount().getValue());
Total Net
The total amount excluding taxes for the invoice
totalNet
of type Amount
logger.info(invoiceDocument.getInference().getDocumentPrediction().getTotalNet().getValue());
Questions?
Updated 27 days ago