Java SDK: OCR Invoices & Receipts in Seconds
Author: Ernest Semerda
It’s rather difficult to write a hook for a technology article. While cooking blogs can ramble about their late grandmother’s inner seam measurement–as if it has something to do with cherry cobbler–technology blogs don’t share the same luxury. I’ll do my best though, so how about a chess story?
Back in the 1920’s–when “artificial intelligence” was a term used to describe drafters of the Treaty of Versailles–there was a chess grandmaster playing a simultaneous game against eight other people.
One fate-tempting amateur told the master, “Sorry, but you will lose in four moves.”
To which the grandmaster only smiled.
“Sorry,” he replied. “It’s my turn, and I’ll be done in three.”
Now, in case you don’t possess the background in literary analysis to understand where I’m going with this, Veryfi is that grandmaster; it’s the future of data extraction, and it’s already made its move.
While there are many ways to perform data extraction, few present an intelligent solution. Although I don’t have a Ph.D. in Data Science, it doesn’t take a degree to tell if a program extracted the fields of an invoice or receipt perfectly. Thankfully, Veryfi does just that using an advanced ICR system to parse documents in seconds.
If you’re in or know people in, accounting, this scenario may seem familiar to you. Imagine you need to record the data of one million financial documents consisting of everything from travel tickets, to contractor invoices, to bills for three-martini lunches. The old-school approach would be to assemble a team of ten people and have each member process as many documents as possible every single day. If each person processes 500 documents per day, around one document per minute, and skips their respective three-martini lunches, it will still take 200 days to complete this task.
And that’s not even the end.
Assuming you’re not Enron, and you’re accurately recording your data, rather than shoveling it all into a big fire and taking an early lunch, you would need to authenticate these entries. That requires another group of people to go through that same stack of documents and double-check that no missing decimal points will have the IRS knocking, wondering why you claimed a $500 write-off on a single cup of coffee.
Perhaps it’s also a bad time to add that soul-crushing and repetitive work is one of the main causes of employee turnover.
Thankfully though, Veryfi has a better solution for recording financial data, and it’s all done in seconds without the need for human oversight or overworked accountants. Through Veryfi, that stack of one million financial documents can be processed in less than a day–try mere hours. That’s because in several seconds, Veryfi can automatically process and extract data from documents, and it can even do the same for thousands of others in parallel. Just like that, Veryfi saved you months of work, valuable employee morale, and money.
This is what Veryfi achieves: the real-time capture and extraction of financial documents into a properly structured data format. Veryfi avoids human error and saves you precious time and money, so how do you use it?
As it turns out, Veryfi is incredibly intuitive and easy to use, especially for developers.
To circle back to that introduction, I’ll tell you another story about chess. Today, the strongest chess program was developed with machine learning. You may know it as Alpha Zero, and it was able to defeat the old programs built with outdated brute force algorithms. Thanks to Alpha Zero, we have better machines, because they actually learn and improve from their prior matches.
It’s this principle of continuous and automatic self-improvement that Veryfi operates on.
Veryfi continues to learn and improve, another key reason our software is so successful. Let’s delve into the details on how to integrate Veryfi with this short project. Veryfi also provides similar projects in other languages like Node.js, Python, Go, and so on. For now, though, we’ll run this show move-by-move like a chess game.
For a better understanding of how this SDK operates, check out the Github README.
Here, you can check out a basic use case before we begin. However, if you already have a coding background, you can always look at the API documentation for the full list of functions.
By the way, this is an open-source project, so feel free to contribute! Just make a pull request, and our team will be ready to review it 😉
Open your Java project and add the following Maven Dependency. If your project already has Maven, just add these lines to your pom.xml file.
<dependency> <groupId>com.veryfi</groupId> <artifactId>veryfi-java</artifactId> <version>1.0.0</version> </dependency>
To use Veryfi, you will need your credentials. Visit our signup page to register or begin a free trial. After you log in, go to settings, and copy the following credentials: clientId, clientSecret, username, apiKey.
Once you have them, add this line in your code to create the Veryfi client on Java. If you’re curious what exactly this client is, you can learn about it here.
Client client = VeryfiClientFactory.createClient(clientId, clientSecret, username, apiKey);
Go to the part of your project you want to call Veryfi to process a document and just call the line below:
String jsonResponse = client.processDocument("receipt.png", null, false, null);
After that, you will have the JSON data from receipt.png ready for you to use.
If you want a more custom solution, Veryfi has plenty of different parameters like categories, deleting the data after processing, and even the ability to specify extra parameters. In fact, there are so many options, you can see the full list in the API docs in your Veryfi Hub.
When the computer first defeated the human in 1997, the landscape of chess was changed forever. Today, the best chess players rely on software to train their skills, and now that same innovation comes to digital accounting thanks to Veryfi. That’s why Veryfi is the frontrunner of automated data extraction and the most reliable and efficient solution for real-time financial document processing.
Head of Mobile Engineering at Veryfi
& Special Thanks to Matthew Eng for help with review.
Any feedback, positive or negative, keeps Veryfi growing and improving! While working with the SDK, you may encounter bugs or issues. If you do, please open an issue on the Veryfi Java SDK Github Repository.
GitHub issues: if you want to leave public feedback, please open a GitHub issue in the Veryfi Java SDK Github Repository. Doing so may also help any other users experiencing the same problem and grow the conversation. We make sure to evaluate issues on our end too, so we can address them in future releases.
Contact us: If you want to speak with our team privately to ask questions, give feedback, or make a feature request, please email us at email@example.com.
You can always make pull requests for new fixes or features to the Veryfi Java SDK. Please ensure your requests are made under the MIT license. Our team also reviews any requests before they’re merged, so unit tests are gladly accepted.