IRONSOFTWAREHOME
USING IRONOCR

How To Create an OCR Receipt Scanner In C#

Kannaopat Udonpant
Kannapat Udonpant
Updated: August 1, 2026

This tutorial is designed to help beginners create an OCR Receipt Scanner using the IronOCR, an OCR API in C#. By the end of this guide, you will understand how to implement optical character recognition (OCR) to convert different types of receipt files into editable and searchable data using receipt OCR API. This technology can be a game-changer for businesses looking to automate expense management and minimize manual data entry. Let's get started!

How To Create an OCR Receipt Scanner In C#

  1. Create a C# Console project in Visual Studio.
  2. Install the OCR library using NuGet Package Manager.
  3. Load the receipt into the program using the OcrInput method.
  4. Extract the text using the Read method.
  5. Show the extracted text on the console.

Prerequisites

Before we dive into the coding part, make sure you have the following:

  1. Visual Studio: This will be our Integrated Development Environment (IDE), where we will write and run our C# code.
  2. IronOCR Library: We will use IronOCR, an advanced OCR library that can be easily integrated into C# applications.
  3. Sample Receipt: A receipt image file named Sample_Receipt.jpg, which we will use to test our OCR implementation.

How To Create an OCR Receipt Scanner In C#: Figure 1 - Image of sample receipt

Step 1: Setting Up the Project

Open Visual Studio: Locate the Visual Studio icon on your desktop or in your applications menu and double-click it to open the program.

Create a New Project: Once Visual Studio is open, you'll find a launch window. Click on the "Create a new project" button. If you have already opened Visual Studio and don't see the launch window, you can access this by clicking File > New > Project from the top menu.

Select Project Type: In the "Create a new project" window, you'll see a variety of project templates. In the search box, type "Console App" to filter the options, then select Console App (.NET Core) or Console App (.NET Framework), depending on your preference and compatibility. Then click the Next button.

Configure Your New Project: Now, you'll see a screen titled "Configure your new project".

  • In the Project name field, enter OCRReceiptScanner as the name of your project.
  • Choose or confirm the location where your project will be saved in the location field.
  • Optionally, you can also specify a solution name if you want it to be different from the project name.
  • Click the Next button after filling in these details.

Additional Information: You might be asked to select the target .NET Framework. Choose the most recent version (unless you have specific compatibility requirements) and click Create.

Step 2: Integrating IronOCR

Before we can use the IronOCR library, we need to include it in our project. Follow these steps:

  1. Right-click on your project in the Solution Explorer.

  2. Choose "Manage NuGet Packages".

  3. In the NuGet Package Manager window, you will see several tabs like Browse, Installed, Updates, and Consolidate. Click on the Browse tab.

  4. In the search box, type IronOCR. This is the name of the library we wish to add to our project. Press enter to search.

  5. The search results will show the IronOCR library package. It should be one of the first results you see. Click on it to select it.

  6. After selecting the IronOCR package, you will notice a panel on the right side displaying the package's information, including its description and version. There is also an Install button in this panel.

    How To Create an OCR Receipt Scanner In C#: Figure 2 - Installing IronOCR through NuGet package manager

  7. Click the Install button. This action might prompt you to review changes and may show a list of dependencies that will be included along with IronOCR. Review the changes and dependencies, and if everything looks correct, confirm and proceed with the installation.

Step 3: Configuring the Project

After installing IronOCR, your next step is to configure your project. Here's how:

Add Namespaces: At the top of your Program.cs file, include the following namespaces:

using IronOcr;
using System;

Configuration Settings: If you have any configuration settings like an API key or a license key, make sure to include them. For IronOCR, you'll need to set the license key as shown in the provided code:

License.LicenseKey = "License-Key"; // replace 'License-Key' with your key

Step 4: Reading the Receipt

Now, let's write the code to read the receipt.

Define the Path to Your Receipt: Specify the path to the receipt file you want to scan.

string pdfFilePath = "Sample_Receipt.jpg";

Try-Catch Block: Implement error handling using a try-catch block. This will help you manage any exceptions that occur during the OCR process.

try
{
    // OCR code will go here
}
catch (Exception ex)
{
    // Handle exceptions here
    Console.WriteLine($"An error occurred: {ex.Message}");
}

Step 5: Implementing OCR

In Step 5, we delve into the core functionality of our application: implementing OCR to read and interpret the data from our receipt. This involves initializing the OCR engine, configuring the input, performing the OCR operation, and displaying the results.

Initialize IronTesseract

The first part of the code creates an instance of the IronTesseract class:

var ocr = new IronTesseract();

By creating an instance of IronTesseract, we are essentially setting up our OCR tool, gearing it up to perform the text recognition tasks. It's like starting the engine of a car before you can drive it. This object will be used to control the OCR process, including reading the input and extracting text from it.

Configure OCR Input

Next, we define the input for our OCR process:

using (var input = new OcrInput(pdfFilePath))
{
    // OCR processing will go here
}

In this segment, OcrInput is used to specify the file we want to process. pdfFilePath is a variable that contains the path to our receipt file. By passing this variable to OcrInput, we are telling the OCR engine, "Here's the file I want you to read." The using statement is a special C# construct that ensures that the resources used by OcrInput (like file handles) are properly released once the processing is done. It's a way to manage resources efficiently and ensure that your application runs smoothly without unnecessary memory usage.

Perform OCR

Within the using block, we call the Read method on our ocr instance:

var result = ocr.Read(input);

The Read method will take the input file path as the parameter. This line will start the receipt scanning. It'll do the OCR of the given input file, extract data, and store it in a variable result. We can use the extracted text from this method to perform any text operation.

Output the Results

Finally, we output the text that was recognized by the OCR process:

Console.WriteLine(result.Text);

The result variable contains the output of the OCR process and result.Text contains the actual text extracted from the receipt. The Console.WriteLine function then takes this text and displays it on the console. This allows you to see and verify the results of the OCR process. Here is the complete Program.cs file code:

using IronOcr;
using System;

class Program
{
    static void Main(string[] args)
    {
        // Set your IronOCR license key
        License.LicenseKey = "Your-License-Key";
        
        // Define the path to the receipt image
        string pdfFilePath = "Sample_Receipt.jpg";

        try
        {
            // Initialize the OCR engine
            var ocr = new IronTesseract();

            // Define the input file
            using (var input = new OcrInput(pdfFilePath))
            {
                // Perform OCR and get the result
                var result = ocr.Read(input);

                // Display the extracted text
                Console.WriteLine(result.Text);
            }
        }
        catch (Exception ex)
        {
            // Handle exceptions and log them if necessary
            Console.WriteLine($"An error occurred: {ex.Message}");
        }
    }
}

Step 6: Running Your Application

  1. Build the Project: Click on the 'Build' menu and then select 'Build Solution'.
  2. Run the Project: Press F5 or click on the 'Start' button to run your application.

Now, you see the text from your receipt output to the console. This text represents the data extracted from your receipt image. It's how we scan receipts using IronOCR. This is a simple example of using OCR capabilities to extract data from paper receipts. It's a very generic implementation. You can modify your code to match the layout of your receipt images.

How To Create an OCR Receipt Scanner In C#: Figure 3 - Outputted text from the previous code example

After that, you can use the unstructured data from receipts that we got after scanning receipts. We can get important information from a particular section of the receipt. Or we can show the receipt data in a more organized way. We can make an OCR Receipt Scanning software application using the IronOCR. That will help us to extract accurate data of receipt fields.

Conclusion

Congratulations! You've successfully built an OCR receipt scanner using C# and IronOCR. This scanner can significantly increase the accuracy of data extraction for various business needs such as expense tracking, supply chain management, and more. There will be no more need to review the scanned receipts and extract data manually.

IronOCR offers a free trial, allowing users to explore and assess its capabilities at no initial cost. For those seeking to integrate and leverage the full spectrum of features in a professional setting, licenses begin at $999, providing a comprehensive solution for robust OCR receipt scanning and data extraction needs.

Remember, this is just the beginning. You can expand this application to support various file types, improve data privacy, or integrate additional features like receipt recognition for specific fields such as tax amount, date, line items, and more. With OCR technology, the possibilities are vast, paving the way for more efficient and intelligent business processes. Happy coding!

Related Articles

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required