Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
A receipt scanning API extracts key data from receipts using advanced OCR technology. It streamlines the data entry process by eliminating manual errors and enhancing productivity. The API, versatile and accurate, supports multiple languages, currencies, and formats. By automating receipt parsing, businesses can gain insights into spending patterns and make data-driven decisions. This article will demonstrate how to use the C# OCR library, IronOCR, to extract important information from a receipt.
IronOCR is a versatile OCR library and API developed by Iron Software, offering developers a powerful solution for extracting text from various sources such as scanned documents, images, and PDFs. With its advanced OCR algorithms, computer vision and machine learning models, IronOCR ensures high accuracy and reliability, even in challenging scenarios. The library supports multiple languages and font styles, making it suitable for global applications. By incorporating IronOCR with machine learning model capabilities into their applications, developers can easily automate data entry, text analysis, and other tasks, enhancing productivity and efficiency.
With IronOCR, developers can effortlessly fetch text from a variety of sources, including documents, photographs, screenshots, and even live camera feeds as JSON responses. By utilizing sophisticated algorithms and machine learning models, IronOCR analyzes the image data, recognizes individual characters, and converts them into machine-readable text. This extracted text can then be used for various purposes, such as data entry, information retrieval, text analysis, and automation of manual tasks.
Before you can start working with IronOCR, there are a few prerequisites that need to be in place. These prerequisites include:
By ensuring that these prerequisites are met, you'll be ready to dive into the process of working with IronOCR.
To get started with IronOCR, the first step is to create a new Visual Studio project.
Open Visual Studio and go to Files, then hover on New, and click on Project.
New Project Image
In the new window, select Console Application and click on Next.
Console Application
A new window will appear. Write the name of your new project, and location and click on Next.
Project Configuration
Finally, provide the Target Framework and click on Create.
Target Framework
Now your new Visual Studio project is created, let's install the IronOCR.
There are several methods for downloading and installing the IronOCR library. However, here are the two simplest approaches.
IronOCR may be included in a C# project by utilizing the Visual Studio NuGet Package Manager.
Navigate to the NuGet Package Manager graphical user interface by selecting Tools > NuGet Package Manager > Manage NuGet Packages for Solution
NuGet Package Manager
After this, a new window will appear. Search for IronOCR and install the package in the project.
IronOCR
Additional language packs for IronOCR can also be installed using the same method described above.
Enter the following line in the Package Manager Console tab:
Install-Package IronOcr
Package Manager Console
The package will now download/install in the current project and be ready to use.
Extracting data from receipt images using IronOCR and saving them in structured data form is a lifesaver for most developers. Using IronOCR, you can achieve that with just a few lines of code. Using this you can extract line items, pricing, tax amount, total amount and many more with different document types.
using IronOcr;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
var ocr = new IronTesseract();
using (var input = new OcrInput(@"r2.png"))
{
var result = ocr.Read(input);
var descriptionPattern = @"\[([A-Z0-9_]+)]\s+(.*?)\s+(\d+\.\d+)\s+Units\s+(\d+\.\d+)\s+Tax15%\s+\$(\d+\.\d+)";
var pricePattern = @"\$\d+(\.\d{2})?";
var descriptions = new List<string>();
var unitPrices = new List<decimal>();
var taxes = new List<decimal>();
var amounts = new List<decimal>();
var lines = result.Text.Split('\n');
var descriptionMatch = Regex.Match(lines, descriptionPattern);
if (descriptionMatch.Success)
{
var DescriptionValue = descriptionMatch.Groups [2].Value.Trim();
descriptions.Add(DescriptionValue);
}
Console.WriteLine("Description: " + descriptions [i]);
Console.WriteLine("Quantity: 1.00 Units");
Console.WriteLine("Unit Price: $" + unitPrices [i]);
taxes.Add(cost [i] * 0.15m); // Calculate Taxes (15%)
Console.WriteLine("Taxes: $" + taxes [i]);
amounts.Add(unitPrices [i] + taxes [i]);
Console.WriteLine("Amount: $" + amounts [i]);
Console.WriteLine("-----------------------");
}
using IronOcr;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
var ocr = new IronTesseract();
using (var input = new OcrInput(@"r2.png"))
{
var result = ocr.Read(input);
var descriptionPattern = @"\[([A-Z0-9_]+)]\s+(.*?)\s+(\d+\.\d+)\s+Units\s+(\d+\.\d+)\s+Tax15%\s+\$(\d+\.\d+)";
var pricePattern = @"\$\d+(\.\d{2})?";
var descriptions = new List<string>();
var unitPrices = new List<decimal>();
var taxes = new List<decimal>();
var amounts = new List<decimal>();
var lines = result.Text.Split('\n');
var descriptionMatch = Regex.Match(lines, descriptionPattern);
if (descriptionMatch.Success)
{
var DescriptionValue = descriptionMatch.Groups [2].Value.Trim();
descriptions.Add(DescriptionValue);
}
Console.WriteLine("Description: " + descriptions [i]);
Console.WriteLine("Quantity: 1.00 Units");
Console.WriteLine("Unit Price: $" + unitPrices [i]);
taxes.Add(cost [i] * 0.15m); // Calculate Taxes (15%)
Console.WriteLine("Taxes: $" + taxes [i]);
amounts.Add(unitPrices [i] + taxes [i]);
Console.WriteLine("Amount: $" + amounts [i]);
Console.WriteLine("-----------------------");
}
Imports Microsoft.VisualBasic
Imports IronOcr
Imports System
Imports System.Collections.Generic
Imports System.Text.RegularExpressions
Private ocr = New IronTesseract()
Using input = New OcrInput("r2.png")
Dim result = ocr.Read(input)
Dim descriptionPattern = "\[([A-Z0-9_]+)]\s+(.*?)\s+(\d+\.\d+)\s+Units\s+(\d+\.\d+)\s+Tax15%\s+\$(\d+\.\d+)"
Dim pricePattern = "\$\d+(\.\d{2})?"
Dim descriptions = New List(Of String)()
Dim unitPrices = New List(Of Decimal)()
Dim taxes = New List(Of Decimal)()
Dim amounts = New List(Of Decimal)()
Dim lines = result.Text.Split(ControlChars.Lf)
Dim descriptionMatch = Regex.Match(lines, descriptionPattern)
If descriptionMatch.Success Then
Dim DescriptionValue = descriptionMatch.Groups (2).Value.Trim()
descriptions.Add(DescriptionValue)
End If
Console.WriteLine("Description: " & descriptions (i))
Console.WriteLine("Quantity: 1.00 Units")
Console.WriteLine("Unit Price: $" & unitPrices (i))
taxes.Add(cost (i) * 0.15D) ' Calculate Taxes (15%)
Console.WriteLine("Taxes: $" & taxes (i))
amounts.Add(unitPrices (i) + taxes (i))
Console.WriteLine("Amount: $" & amounts (i))
Console.WriteLine("-----------------------")
End Using
As you can see below, IronOCR can easily extract the required text from the receipt.
Output
If you want to extract the whole receipt, you can easily do this with a few lines of code on the OCR receipt.
using IronOcr;
using System;
var ocr = new IronTesseract();
using (var input = new OcrInput(@"r3.png"))
{
var result = ocr.Read(input);
Console.WriteLine(result.Text);
}
using IronOcr;
using System;
var ocr = new IronTesseract();
using (var input = new OcrInput(@"r3.png"))
{
var result = ocr.Read(input);
Console.WriteLine(result.Text);
}
Imports IronOcr
Imports System
Private ocr = New IronTesseract()
Using input = New OcrInput("r3.png")
Dim result = ocr.Read(input)
Console.WriteLine(result.Text)
End Using
Scan receipt API output
The receipt image scanning API, such as IronOCR, offers a powerful software solution for automating the extraction of data from receipts. By leveraging advanced OCR technology, businesses can easily extract important information from receipt images or scans, including business vendor names, purchase dates, itemized lists, prices, taxes, and total amounts. With support for multiple languages, currencies, receipt formats, and barcode support, businesses can streamline their receipt management processes, save time, gain insights into spending patterns, and make data-driven decisions. IronOCR, as a versatile OCR library and API, provides developers with the tools they need to extract text from various sources accurately and efficiently, enabling automation of tasks and improving overall efficiency. By meeting the necessary prerequisites and integrating IronOCR into their applications, developers can unlock the benefits of receipt data processing and enhance their workflows.
For more information on IronOCR, visit this licensing page. To know about how to use computer vision to find text, visit this computer vision how-to page. For more tutorials on receipt OCR, visit the following OCR C# tutorial.
9 .NET API products for your office documents