フッターコンテンツにスキップ
IRONOCRの使い方

請求書OCR API(開発者チュートリアル)

Invoice OCR API utilizes machine learning and computer vision to transform invoice data into a format suitable for automated processing. This technology addresses manual data entry issues like delays, costs, and errors, accurately extracting details like vendor information, invoice numbers, and prices from both digital and scanned invoices.

This article will use a top-of-the-line invoice OCR API named IronOCR.

1. IronOCR

IronOCR, developed by Iron Software, is an OCR library offering a range of tools for developers. It uses machine learning and computer vision to extract text from scanned documents, images, and PDFs, enabling automated processing. Its APIs integrate into various languages and platforms, reducing manual data entry errors and improving efficiency. Extracted data can be analyzed and integrated into existing systems, aiding decision-making and productivity. Features like image preprocessing, barcode recognition, and file parsing increase its versatility. IronOCR empowers developers to incorporate text recognition into their applications.

2. Prerequisites

Before you can start working with IronOCR, there are a few prerequisites that need to be in place. These prerequisites include:

  1. Ensure that you have a suitable development environment set up on your computer. This typically involves having an Integrated Development Environment (IDE) such as Visual Studio installed.
  2. It's important to have a basic understanding of the C# programming language. This will enable you to comprehend and modify the code examples provided in the article effectively.
  3. You'll need to have the IronOCR library installed in your project. This can be accomplished by using the NuGet Package Manager within Visual Studio or through the command line interface.

By ensuring that these prerequisites are met, you'll be ready to dive into the process of working with IronOCR.

3. Creating a New Visual Studio Project

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.

Invoice OCR API (Developer Tutorial): Figure 1 - New Project New Project

In the new window, select Console Application and click on Next.

Invoice OCR API (Developer Tutorial): Figure 2 - Console Application Console Application

A new window will appear, write the name of your new project, and location and click on Next.

Invoice OCR API (Developer Tutorial): Figure 3 - Project Configuration Project Configuration

Finally, provide the Target framework and click on Create.

Invoice OCR API (Developer Tutorial): Figure 4 - Target Framework Target Framework

Now your new Visual Studio project is created. Let's install IronOCR.

4. Installing IronOCR

There are several methods for downloading and installing the IronOCR library. But here are the two simplest approaches.

  1. Using the Visual Studio NuGet Package Manager
  2. Using the Visual Studio Command Line

4.1. Using the Visual Studio NuGet Package Manager

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

Invoice OCR API (Developer Tutorial): Figure 5 - NuGet Package Manager NuGet Package Manager

After this, a new window will appear. Search for IronOCR and install the package in the project.

Invoice OCR API (Developer Tutorial): Figure 6 - Select the IronOCR package in NuGet Package Manager UI Select the IronOCR package in NuGet Package Manager UI

Additional language packs for IronOCR can also be installed using the same method described above.

4.2. Using the Visual Studio Command-Line

  1. In Visual Studio, go to Tools > NuGet Package Manager > Package Manager Console
  2. Enter the following line in the Package Manager Console tab to install IronOCR:

    Install-Package IronOcr

Invoice OCR API (Developer Tutorial): Figure 7 - Package Manager Console Package Manager Console

The package will now download/install in the current project and be ready to use.

5. Extract data from Invoices using IronOCR

Using IronOCR, you can easily extract data from invoices with just a few lines of code and use that data extraction for further processes like data entry. This will replace manual data entry and many more.

Here is an example invoice to extract text from.

Invoice OCR API (Developer Tutorial): Figure 8 - The sample invoice The sample invoice

Now, let's write the code to extract all the data from this invoice.

using IronOcr;
using System;

// Initialize a new instance of the IronTesseract class
var ocr = new IronTesseract();

// Use the OcrInput object to load the image file
using (var input = new OcrInput(@"r2.png"))
{
    // Read the image using the Read method, which performs OCR
    var result = ocr.Read(input);

    // Output the extracted text to the console
    Console.WriteLine(result.Text);
}
using IronOcr;
using System;

// Initialize a new instance of the IronTesseract class
var ocr = new IronTesseract();

// Use the OcrInput object to load the image file
using (var input = new OcrInput(@"r2.png"))
{
    // Read the image using the Read method, which performs OCR
    var result = ocr.Read(input);

    // Output the extracted text to the console
    Console.WriteLine(result.Text);
}
Imports IronOcr
Imports System

' Initialize a new instance of the IronTesseract class
Private ocr = New IronTesseract()

' Use the OcrInput object to load the image file
Using input = New OcrInput("r2.png")
	' Read the image using the Read method, which performs OCR
	Dim result = ocr.Read(input)

	' Output the extracted text to the console
	Console.WriteLine(result.Text)
End Using
$vbLabelText   $csharpLabel

The above code gets input in the form of an image and then extracts data from that image using a Read method from the IronTesseract class.

Invoice OCR API (Developer Tutorial): Figure 9 - Invoice Parser Invoice Parser

5.1. Invoice Processing to extract specific data from invoices

You can also extract specific data from invoices like customer invoice numbers. Below is the code to extract the customer invoice number from the invoice.

using IronOcr;
using System;
using System.Text.RegularExpressions;

// Initialize a new instance of the IronTesseract class
var ocr = new IronTesseract();

// Use the OcrInput object to load the image file
using (var input = new OcrInput(@"r2.png"))
{
    // Perform OCR on the image
    var result = ocr.Read(input);

    // Define a regular expression pattern for the invoice number
    var linePattern = @"INV\/\d{4}\/\d{5}";

    // Match the pattern in the extracted text
    var lineMatch = Regex.Match(result.Text, linePattern);

    // Check if the pattern matches any part of the text
    if (lineMatch.Success)
    {
        // If a match is found, print the invoice number
        var lineValue = lineMatch.Value;
        Console.WriteLine("Customer Invoice number: " + lineValue);
    }
}
using IronOcr;
using System;
using System.Text.RegularExpressions;

// Initialize a new instance of the IronTesseract class
var ocr = new IronTesseract();

// Use the OcrInput object to load the image file
using (var input = new OcrInput(@"r2.png"))
{
    // Perform OCR on the image
    var result = ocr.Read(input);

    // Define a regular expression pattern for the invoice number
    var linePattern = @"INV\/\d{4}\/\d{5}";

    // Match the pattern in the extracted text
    var lineMatch = Regex.Match(result.Text, linePattern);

    // Check if the pattern matches any part of the text
    if (lineMatch.Success)
    {
        // If a match is found, print the invoice number
        var lineValue = lineMatch.Value;
        Console.WriteLine("Customer Invoice number: " + lineValue);
    }
}
Imports IronOcr
Imports System
Imports System.Text.RegularExpressions

' Initialize a new instance of the IronTesseract class
Private ocr = New IronTesseract()

' Use the OcrInput object to load the image file
Using input = New OcrInput("r2.png")
	' Perform OCR on the image
	Dim result = ocr.Read(input)

	' Define a regular expression pattern for the invoice number
	Dim linePattern = "INV\/\d{4}\/\d{5}"

	' Match the pattern in the extracted text
	Dim lineMatch = Regex.Match(result.Text, linePattern)

	' Check if the pattern matches any part of the text
	If lineMatch.Success Then
		' If a match is found, print the invoice number
		Dim lineValue = lineMatch.Value
		Console.WriteLine("Customer Invoice number: " & lineValue)
	End If
End Using
$vbLabelText   $csharpLabel

Invoice OCR API (Developer Tutorial): Figure 10 - Invoice Scanning Invoice Scanning

6. Conclusion

IronOCR's Invoice OCR API revolutionizes data extraction from invoices using machine learning and computer vision. This technology converts invoice text and numbers into a machine-readable format, simplifying data extraction for analysis, integration, and process improvement. It offers a robust solution for automating invoice processing, improving accuracy, and optimizing workflows like accounts payable. Automated data entry from scanned invoices is also made possible with this technology.

IronOCR offers high accuracy using the best results from Tesseract, without any additional settings. It supports multipage frame TIFF, PDF files, and all popular image formats. It is also possible to read barcode values from images.

Please visit the homepage website for more information on IronOCR. For more tutorials on invoice OCR, visit the following this details invoice OCR tutorial. To know about how to use computer vision to find text such as invoice fields, visit this computer vision how-to.

よくある質問

OCRを使用してインボイスデータ処理をどのように自動化できますか?

IronOCRを使用して機械学習アルゴリズムを活用することで、インボイスデータ処理を自動化できます。IronOCRは、デジタルおよびスキャンされたインボイスからベンダー情報、インボイス番号、価格などの詳細を抽出し、手動入力のエラーを減らし、効率を向上させます。

インボイスOCR APIのセットアップにはどのような手順が含まれていますか?

IronOCRを使用してインボイスOCR APIをセットアップするには、まずVisual StudioのNuGetパッケージマネージャーを介してライブラリをダウンロードしてインストールします。次に、新しいC#プロジェクトを作成し、IronOCRを統合し、テキスト抽出のために画像ファイルを読み込み、読み取るためのメソッドを使用します。

IronOCRはインボイス番号などの特定のデータを抽出できますか?

はい、IronOCRはインボイス番号のような特定のデータを抽出できます。通常の表現を使用して抽出されたテキストのパターンと一致させることで、インボイスから特定の情報を引き出せます。

インボイス処理に役立つIronOCRのいくつかの機能は何ですか?

IronOCRには、画像の前処理、バーコード認識、ファイル解析などの機能があります。これにより、さまざまな請求書形式からテキストを正確に抽出および処理する能力が向上し、データキャプチャおよびワークフローの効率が改善されます。

画像の前処理はどのようにしてOCRの結果を改善できますか?

IronOCRの画像前処理は、テキスト抽出前に画像の品質を最適化することで、OCRの結果を改善します。これには、コントラスト調整やノイズ削減などの操作が含まれ、インボイスからのデータ抽出の精度を高めることができます。

デジタルおよびスキャンされたインボイスの両方にIronOCRを使用することは可能ですか?

はい、IronOCRはデジタルおよびスキャンされた両方のインボイスを処理できます。先進的な機械学習およびコンピュータビジョン技術を使用して、さまざまな形式および画像品質から正確にテキストを抽出します。

IronOCRは複数のページ形式およびファイルタイプをどのように処理しますか?

IronOCRは、複数のページ形式および一般的な画像およびPDFファイルタイプをサポートしています。複雑なドキュメントから効率的にテキストを抽出できるため、さまざまなインボイス処理アプリケーションにおいて非常に柔軟です。

開発者はIronOCRを使用するためのチュートリアルをどこで見つけることができますか?

開発者はIronOCRのウェブサイトでチュートリアルや追加のリソースを見つけることができます。このサイトは、さまざまな状況でIronOCRを適用するためのハウツーガイドやブログ投稿を含む幅広い学習資料を提供しています。

Kannaopat Udonpant
ソフトウェアエンジニア
ソフトウェアエンジニアになる前に、Kannapatは北海道大学で環境資源の博士号を修了しました。博士号を追求する間に、彼はバイオプロダクションエンジニアリング学科の一部である車両ロボティクスラボラトリーのメンバーになりました。2022年には、C#のスキルを活用してIron Softwareのエンジニアリングチームに参加し、IronPDFに注力しています。Kannapatは、IronPDFの多くのコードを執筆している開発者から直接学んでいるため、この仕事を大切にしています。同僚から学びながら、Iron Softwareでの働く社会的側面も楽しんでいます。コードやドキュメントを書いていない時は、KannapatはPS5でゲームをしたり、『The Last of Us』を再視聴したりしていることが多いです。