跳至頁尾內容
使用 IRONOCR

發票 OCR API(開發者教學)

發票 OCR API 利用機器學習技術自動提取發票數據,消除手動輸入錯誤,同時準確地從電子文件和掃描文件中捕獲供應商詳細資訊、發票號碼和價格。 本教學課程示範如何使用 IronOCR 建立發票 OCR 解決方案。

透過利用機器學習和電腦視覺技術,發票 OCR 技術將發票資料轉換為可供自動處理的格式。 您將學習如何應對常見的挑戰,例如手動資料輸入延遲、成本和錯誤,同時準確地從任何發票格式中提取供應商資訊、發票號碼和價格。

本文使用了IronOCR ,這是一款領先的 .NET 開發人員的發票 OCR API。

什麼是IronOCR?

IronOCR 由 Iron Software 開發,為開發人員提供全面的 OCR 工具。 它利用機器學習和電腦視覺技術從掃描文件、圖像和 PDF 中提取文本,以實現自動化處理。 其 API 可與各種語言和平台無縫集成,減少人工資料輸入錯誤,提高效率。 提取的數據直接流入現有系統進行分析和決策。 影像預處理條碼識別和靈活的檔案解析等功能增強了其多功能性。 IronOCR 使開發人員能夠將強大的文字辨識功能整合到他們的應用程式中。

該庫透過專門的語言包支援125 種國際語言,使其成為全球發票處理的理想選擇。 高級功能包括電腦視覺技術,可自動找到文本,這對於佈局各異的發票尤其有用。 此外,IronOCR 還提供多執行緒處理功能,可有效處理大量發票處理。

為什麼我應該使用 IronOCR 進行發票處理?

IronOCR 為發票處理應用提供了顯著優勢。 首先,它透過其優化的Tesseract 5 引擎提供卓越的精度,該引擎專門針對 .NET 應用程式進行了增強。 圖書館可以處理各種發票格式,從掃描文件PDF 文件,甚至是低品質掃描件

內建影像最佳化濾鏡可在處理前自動增強影像質量,從而實現更準確的文字擷取。 對於有特殊要求的發票,IronOCR 支援自訂語言訓練,可針對發票類型中常見的獨特字體或格式進行最佳化。

IronOCR 與其他 OCR 庫有何不同?

IronOCR 的獨特之處在於其簡單的單行 OCR 功能,同時又具備企業級功能。 與原始的 Tesseract 實作不同,IronOCR 提供了一個託管的 .NET API,可以無縫地處理複雜的操作。 該程式庫為各種文件類型提供專門的文件讀取方法,包括專門支援讀取文件中的表格,這對於發票明細項目至關重要。

篩選精靈會自動確定特定發票影像的最佳預處理設置,從而消除優化過程中的猜測。 IronOCR 還提供全面的調試功能,使開發人員能夠視覺化 OCR 引擎所看到的內容,並有效地排除提取問題。

我需要哪些先決條件?

在使用 IronOCR 之前,請確保滿足以下先決條件:

  1. 已安裝諸如 Visual Studio 之類的整合開發環境 (IDE),並具備合適的開發環境。
  2. 具備C#程式設計基礎知識,能夠有效地理解並修改程式碼範例。
  3. 透過 NuGet 套件管理器或命令列將 IronOCR 庫安裝到您的專案中

滿足這些先決條件後,您就可以成功地開始使用 IronOCR 了。

IronOCR 提供適用於WindowsLinuxmacOS的全面設定指南。 該程式庫支援雲端部署,並針對AWS LambdaAzure Functions提供了專門的教程。

我該使用哪個版本的 Visual Studio?

IronOCR 支援 Visual Studio 2017 及最新版本。 為了獲得最佳相容性並能使用最新的 C# 功能,建議使用 Visual Studio 2019 或 2022。 此程式庫與.NET Framework、.NET Core 和 .NET 5+完全相容,確保您的開發環境具有靈活性。

對於跨平台開發,具有 C# 擴充功能的 Visual Studio Code 效果很好。 行動開發人員可以利用 IronOCR 針對AndroidiOS實現的指導,使其適用於.NET MAUI 應用程式

我需要具備怎樣的 C# 知識水準?

具備中級 C# 知識即可實現基本的發票 OCR 功能。 你應該能夠適應:

IronOCR 直覺的 API 設計意味著無需具備影像處理或機器學習方面的深厚專業知識。 該庫在內部處理複雜的操作,讓您可以專注於業務邏輯。 初學者可以從簡單的OCR範例入手。

如何建立一個新的 Visual Studio 專案?

要開始使用 IronOCR,首先需要建立一個新的 Visual Studio 專案。

開啟 Visual Studio,轉到"檔案",將滑鼠懸停在"新建"上,然後按一下"專案"。

Visual Studio IDE 顯示"檔案"選單已打開,"新"和"專案"選項已高亮顯示,示範了建立新的發票 OCR API 專案的第一步。 新專案

在新視窗中,選擇"控制台應用程式",然後按一下"下一步"。

Visual Studio 的"建立新專案"對話方塊顯示了各種專案模板,其中"控制台應用程式"選項突出顯示,用於建立適用於發票 OCR 處理的 .NET Core 命令列應用程式。 控制台應用程式

一個新的視窗出現。 請輸入項目名稱和地點,然後按一下"下一步"。

Visual Studio 新專案設定視窗顯示了名為"IronOCR"的控制台應用程式的專案設置,其中選擇了 C# 語言和 Windows 目標平台,用於發票 OCR API 實作。 專案配置

最後,選擇目標框架並點擊"建立"。

Visual Studio 專案建立精靈顯示了"附加資訊"步驟,其中已選擇 .NET 5.0 框架,以便在發票處理應用程式中實現最佳的 IronOCR 相容性。 目標框架

你的新 Visual Studio 專案已準備就緒。 我們來安裝IronOCR。

哪種專案類型最適合 OCR 應用?

雖然本教程為了簡單起見使用了控制台應用程序,但 IronOCR 支援多種項目類型:

-控制台應用程式:非常適合批次處理或命令列工具

  • Web 應用程式:非常適合建立 API 或基於 Web 的服務
  • Windows Forms/WPF :適用於具有圖形使用者介面的桌面應用程式
  • .NET MAUI 應用:用於跨平台解決方案

對於大批量處理,可以考慮在 Windows 服務或微服務架構中實作 IronOCR。 圖書館的進度追蹤功能使監控長時間運作的操作變得容易。

我該選擇哪個 .NET Framework 版本?

IronOCR與 .NET 版本具有廣泛的兼容性。 對於新項目,建議使用 .NET 6.0 或更高版本以獲得最佳效能和最新功能。 該庫保持了出色的向後相容性:

  • .NET Framework 4.6.2+ :適用於傳統企業應用程式
  • .NET Core 3.1 :長期支持,實現穩定部署
  • .NET 5.0+ :效能提升的現代化框架
  • .NET Standard 2.0 :跨平台最大程度的相容性

部署到Docker 容器時,.NET 6.0 或更高版本可提供更小的映像大小和更好的效能。 Azure Functions同時支援 .NET 6.0 和 .NET Framework。

如何安裝 IronOCR?

下載和安裝 IronOCR 有兩種簡單的方法:

  1. 使用 Visual Studio NuGet 套件管理器
  2. 使用 Visual Studio 命令列

何時應該使用 NuGet 套件管理器,何時應該使用命令列?

根據您的工作流程,選擇使用 NuGet 套件管理器圖形使用者介面 (GUI) 或命令列:

NuGet 套件管理器 GUI在下列情況下效果最佳: 您是 NuGet 套件的新手 您想瀏覽IronOCR 語言包 您更喜歡視覺確認 您管理多個包裹

命令列(軟體包管理器控制台)在以下情況下表現出色: 您熟悉命令列介面

  • 您遵循腳本化部署 您需要快速取得特定版本。
  • 您使用了進階安裝選項

兩種方法都能達到相同的效果-根據舒適度和需求選擇即可。

我可能還需要哪些額外的語言包?

IronOCR 透過專用軟體套件支援125 種國際語言。 發票處理時,請考慮以下事項:

-特定業務包:財務文件的財務語言包 -區域語言:依發票來源而定(西班牙語、法語、德語) -多語言支援:適用於包含多種語言的發票 -自訂語言:用於特殊字體或自訂訓練數據

語言套件與 IronOCR 主程式包一起安裝,可顯著提高非英語文字的辨識準確率。

使用 Visual Studio NuGet 套件管理器

使用 Visual Studio NuGet 套件管理器將 IronOCR 整合到您的 C# 專案中。

導覽至"工具" > "NuGet 套件管理員" > "管理解決方案的 NuGet 套件"。

Visual Studio IDE 顯示 NuGet 套件管理器介面,其中包含 IronOCR 套件的搜尋結果,並顯示用於設定發票 OCR 功能的安裝選項和套件詳細資訊NuGet 套件管理器

搜尋 IronOCR 並將其安裝到您的專案中。

NuGet 套件管理器介面顯示 IronOCR v2022.1.0 及相關語言套件,包括阿拉伯語、希伯來語和西班牙語 OCR 功能,並顯示每個專用識別包的版本號和描述。 在 NuGet 套件管理器介面中選擇 IronOCR 套件。

使用相同的方法安裝其他語言套件。

使用 Visual Studio 命令列

  1. 在 Visual Studio 中,前往"工具" > "NuGet 套件管理器" > "套件管理器控制台"。
  2. 在軟體包管理器控制台中輸入以下命令:

    Install-Package IronOcr

Visual Studio 套件管理器控制台顯示"Install-Package IronOCR"命令已成功執行,並示範了 OCR 庫的命令列安裝方法。 軟體包管理器控制台

該軟體包將下載並安裝到您目前的專案中,即可使用。

如何使用 IronOCR 從發票中提取資料?

使用 IronOCR,只需幾行代碼即可輕鬆提取發票資料。 它取代了手動資料錄入,簡化了您的工作流程。

以下是一個用於文字提取的發票範例:

範例發票文檔,顯示客戶詳細信息,發票編號 INV/2023/00039,包含三項清潔服務,總計 80.50 美元,展示了用於 OCR 提取的典型發票格式。 發票範本

讓我們從這張發票中提取所有資料:

using IronOcr;
using System;

// Initialize a new instance of the IronTesseract class
// This is the main OCR engine that will process our invoice
var ocr = new IronTesseract();

// Configure OCR settings for better invoice processing
ocr.Configuration.BlackListCharacters = "~`$#^*_}{]___PROTECTED_LINK_48___ method from ___PROTECTED_LINK_49___ class. Key enhancements include:

- **Image preprocessing**: ___PROTECTED_LINK_50___ corrects tilted scans; ___PROTECTED_LINK_51___ removes artifacts
- **Resolution enhancement**: Setting ___PROTECTED_LINK_52___ improves recognition
- **Character blacklisting**: Prevents common OCR misinterpretations
- **Confidence scoring**: Assesses extraction reliability

!___PROTECTED_LINK_53___
**Invoice Parser**

### How Do I Handle Different Invoice Formats?

Invoice formats vary between vendors, but IronOCR provides flexible solutions:

1. **Template-based**: Define ___PROTECTED_LINK_54___
2. **Computer vision**: Use ___PROTECTED_LINK_55___ to locate text
3. **Table extraction**: Leverage ___PROTECTED_LINK_56___ for line items
4. **Multi-format**: Process ___PROTECTED_LINK_57___, ___PROTECTED_LINK_58___, and ___PROTECTED_LINK_59___

For complex layouts, implement the ___PROTECTED_LINK_60___ which uses machine learning to identify structures automatically.

### What Are Common Extraction Patterns for Invoice Data?

Invoice data follows recognizable patterns extractable using regular expressions with OCR results:

```csharp
using IronOcr;
using System;
using System.Text.`RegularExpressions`;
using System.Collections.Generic;

public class `InvoiceDataExtractor`
{
    private readonly `IronTesseract` ocr;

    public `InvoiceDataExtractor`()
    {
        ocr = new `IronTesseract`();
        // Configure for optimal invoice reading
        `ocr.Configuration`.`ReadBarcodes` = true; // Many invoices include barcodes
        `ocr.Configuration`.`TesseractVersion` = `TesseractVersion`.Tesseract5;
    }

    public `InvoiceData` `ExtractInvoiceData`(string imagePath)
    {
        var invoiceData = new `InvoiceData`();

        using (var input = new `OcrInput`(imagePath))
        {
            // Apply filters for better accuracy
            input.`EnhanceResolution`(300);
            `input.Sharpen`();

            var result = `ocr.Read`(input);
            var text = `result.Text`;

            // Extract invoice number
            invoiceData.`InvoiceNumber` = `ExtractPattern`(text, 
                @"INV[/-]?\d{4}[/-]?\d{5}|Invoice\s*#?\s*:?\s*(\d+)");

            // Extract dates
            invoiceData.`InvoiceDate` = `ExtractDate`(text, 
                @"Invoice\s*Date\s*:?\s*(\d{1,2}[/-]\d{1,2}[/-]\d{2,4})");
            invoiceData.`DueDate` = `ExtractDate`(text, 
                @"Due\s*Date\s*:?\s*(\d{1,2}[/-]\d{1,2}[/-]\d{2,4})");

            // Extract amounts
            `invoiceData.Total` = `ExtractAmount`(text, 
                @"Total\s*:?\s*\$?\s*([\d,]+\.?\d*)");
            `invoiceData.Tax` = `ExtractAmount`(text, 
                @"Tax\s*:?\s*\$?\s*([\d,]+\.?\d*)");

            // Extract vendor information
            invoiceData.`VendorName` = `ExtractVendorName`(text);

            // Extract line items using table detection
            invoiceData.`LineItems` = `ExtractLineItems`(result);

            // Extract any barcodes found
            if (`result.Barcodes`.Length > 0)
            {
                invoiceData.`BarcodeValues` = new List<string>();
                foreach (var barcode in `result.Barcodes`)
                {
                    invoiceData.`BarcodeValues`.Add(`barcode.Value`);
                }
            }
        }

        return invoiceData;
    }

    private string `ExtractPattern`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        return `match.Success` ? `match.Value` : `string.Empty`;
    }

    private `DateTime`? `ExtractDate`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        if (`match.Success` && `match.Groups`.Count > 1)
        {
            if (`DateTime`.`TryParse`(`match.Groups`[1].Value, out `DateTime` date))
                return date;
        }
        return null;
    }

    private decimal `ExtractAmount`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        if (`match.Success` && `match.Groups`.Count > 1)
        {
            var amountStr = `match.Groups`[1].Value.Replace(",", "");
            if (decimal.`TryParse`(amountStr, out decimal amount))
                return amount;
        }
        return 0;
    }

    private string `ExtractVendorName`(string text)
    {
        // Usually the vendor name appears in the first few lines
        var lines = `text.Split`('\n');
        if (`lines.Length` > 0)
        {
            // Simple heuristic: first non-empty line that's not a common header
            foreach (var line in lines)
            {
                var trimmed = `line.Trim`();
                if (!string.`IsNullOrEmpty`(trimmed) && 
                    !trimmed.`ToLower`().Contains("invoice") &&
                    `trimmed.Length` > 3)
                {
                    return trimmed;
                }
            }
        }
        return `string.Empty`;
    }

    private List<`LineItem`> `ExtractLineItems`(`OcrResult` result)
    {
        var lineItems = new List<`LineItem`>();

        // Use IronOCR's table detection capabilities
        if (`result.Tables` != null && `result.Tables`.Count > 0)
        {
            foreach (var table in `result.Tables`)
            {
                // Process each row as a potential line item
                for (int i = 1; i < table.`RowCount`; i++) // Skip header row
                {
                    var item = new `LineItem`
                    {
                        Description = table[i, 0]?.Text ?? "",
                        Quantity = `ParseQuantity`(table[i, 1]?.Text),
                        `UnitPrice` = `ParseAmount`(table[i, 2]?.Text),
                        Total = `ParseAmount`(table[i, 3]?.Text)
                    };

                    if (!string.`IsNullOrEmpty`(`item.Description`))
                        `lineItems.Add`(item);
                }
            }
        }

        return lineItems;
    }

    private int `ParseQuantity`(string text)
    {
        if (string.`IsNullOrEmpty`(text)) return 0;
        var cleaned = Regex.Replace(text, @"[^\d]", "");
        return int.`TryParse`(cleaned, out int qty) ? qty : 0;
    }

    private decimal `ParseAmount`(string text)
    {
        if (string.`IsNullOrEmpty`(text)) return 0;
        var cleaned = Regex.Replace(text, @"[^\d.]", "");
        return decimal.`TryParse`(cleaned, out decimal amt) ? amt : 0;
    }
}

// Data classes for structured invoice information
public class `InvoiceData`
{
    public string `InvoiceNumber` { get; set; }
    public `DateTime`? `InvoiceDate` { get; set; }
    public `DateTime`? `DueDate` { get; set; }
    public string `VendorName` { get; set; }
    public decimal Total { get; set; }
    public decimal Tax { get; set; }
    public List<`LineItem`> `LineItems` { get; set; }
    public List<string> `BarcodeValues` { get; set; }
}

public class `LineItem`
{
    public string Description { get; set; }
    public int Quantity { get; set; }
    public decimal `UnitPrice` { get; set; }
    public decimal Total { get; set; }
}
using IronOcr;
using System;

// Initialize a new instance of the IronTesseract class
// This is the main OCR engine that will process our invoice
var ocr = new IronTesseract();

// Configure OCR settings for better invoice processing
ocr.Configuration.BlackListCharacters = "~`$#^*_}{]___PROTECTED_LINK_48___ method from ___PROTECTED_LINK_49___ class. Key enhancements include:

- **Image preprocessing**: ___PROTECTED_LINK_50___ corrects tilted scans; ___PROTECTED_LINK_51___ removes artifacts
- **Resolution enhancement**: Setting ___PROTECTED_LINK_52___ improves recognition
- **Character blacklisting**: Prevents common OCR misinterpretations
- **Confidence scoring**: Assesses extraction reliability

!___PROTECTED_LINK_53___
**Invoice Parser**

### How Do I Handle Different Invoice Formats?

Invoice formats vary between vendors, but IronOCR provides flexible solutions:

1. **Template-based**: Define ___PROTECTED_LINK_54___
2. **Computer vision**: Use ___PROTECTED_LINK_55___ to locate text
3. **Table extraction**: Leverage ___PROTECTED_LINK_56___ for line items
4. **Multi-format**: Process ___PROTECTED_LINK_57___, ___PROTECTED_LINK_58___, and ___PROTECTED_LINK_59___

For complex layouts, implement the ___PROTECTED_LINK_60___ which uses machine learning to identify structures automatically.

### What Are Common Extraction Patterns for Invoice Data?

Invoice data follows recognizable patterns extractable using regular expressions with OCR results:

```csharp
using IronOcr;
using System;
using System.Text.`RegularExpressions`;
using System.Collections.Generic;

public class `InvoiceDataExtractor`
{
    private readonly `IronTesseract` ocr;

    public `InvoiceDataExtractor`()
    {
        ocr = new `IronTesseract`();
        // Configure for optimal invoice reading
        `ocr.Configuration`.`ReadBarcodes` = true; // Many invoices include barcodes
        `ocr.Configuration`.`TesseractVersion` = `TesseractVersion`.Tesseract5;
    }

    public `InvoiceData` `ExtractInvoiceData`(string imagePath)
    {
        var invoiceData = new `InvoiceData`();

        using (var input = new `OcrInput`(imagePath))
        {
            // Apply filters for better accuracy
            input.`EnhanceResolution`(300);
            `input.Sharpen`();

            var result = `ocr.Read`(input);
            var text = `result.Text`;

            // Extract invoice number
            invoiceData.`InvoiceNumber` = `ExtractPattern`(text, 
                @"INV[/-]?\d{4}[/-]?\d{5}|Invoice\s*#?\s*:?\s*(\d+)");

            // Extract dates
            invoiceData.`InvoiceDate` = `ExtractDate`(text, 
                @"Invoice\s*Date\s*:?\s*(\d{1,2}[/-]\d{1,2}[/-]\d{2,4})");
            invoiceData.`DueDate` = `ExtractDate`(text, 
                @"Due\s*Date\s*:?\s*(\d{1,2}[/-]\d{1,2}[/-]\d{2,4})");

            // Extract amounts
            `invoiceData.Total` = `ExtractAmount`(text, 
                @"Total\s*:?\s*\$?\s*([\d,]+\.?\d*)");
            `invoiceData.Tax` = `ExtractAmount`(text, 
                @"Tax\s*:?\s*\$?\s*([\d,]+\.?\d*)");

            // Extract vendor information
            invoiceData.`VendorName` = `ExtractVendorName`(text);

            // Extract line items using table detection
            invoiceData.`LineItems` = `ExtractLineItems`(result);

            // Extract any barcodes found
            if (`result.Barcodes`.Length > 0)
            {
                invoiceData.`BarcodeValues` = new List<string>();
                foreach (var barcode in `result.Barcodes`)
                {
                    invoiceData.`BarcodeValues`.Add(`barcode.Value`);
                }
            }
        }

        return invoiceData;
    }

    private string `ExtractPattern`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        return `match.Success` ? `match.Value` : `string.Empty`;
    }

    private `DateTime`? `ExtractDate`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        if (`match.Success` && `match.Groups`.Count > 1)
        {
            if (`DateTime`.`TryParse`(`match.Groups`[1].Value, out `DateTime` date))
                return date;
        }
        return null;
    }

    private decimal `ExtractAmount`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        if (`match.Success` && `match.Groups`.Count > 1)
        {
            var amountStr = `match.Groups`[1].Value.Replace(",", "");
            if (decimal.`TryParse`(amountStr, out decimal amount))
                return amount;
        }
        return 0;
    }

    private string `ExtractVendorName`(string text)
    {
        // Usually the vendor name appears in the first few lines
        var lines = `text.Split`('\n');
        if (`lines.Length` > 0)
        {
            // Simple heuristic: first non-empty line that's not a common header
            foreach (var line in lines)
            {
                var trimmed = `line.Trim`();
                if (!string.`IsNullOrEmpty`(trimmed) && 
                    !trimmed.`ToLower`().Contains("invoice") &&
                    `trimmed.Length` > 3)
                {
                    return trimmed;
                }
            }
        }
        return `string.Empty`;
    }

    private List<`LineItem`> `ExtractLineItems`(`OcrResult` result)
    {
        var lineItems = new List<`LineItem`>();

        // Use IronOCR's table detection capabilities
        if (`result.Tables` != null && `result.Tables`.Count > 0)
        {
            foreach (var table in `result.Tables`)
            {
                // Process each row as a potential line item
                for (int i = 1; i < table.`RowCount`; i++) // Skip header row
                {
                    var item = new `LineItem`
                    {
                        Description = table[i, 0]?.Text ?? "",
                        Quantity = `ParseQuantity`(table[i, 1]?.Text),
                        `UnitPrice` = `ParseAmount`(table[i, 2]?.Text),
                        Total = `ParseAmount`(table[i, 3]?.Text)
                    };

                    if (!string.`IsNullOrEmpty`(`item.Description`))
                        `lineItems.Add`(item);
                }
            }
        }

        return lineItems;
    }

    private int `ParseQuantity`(string text)
    {
        if (string.`IsNullOrEmpty`(text)) return 0;
        var cleaned = Regex.Replace(text, @"[^\d]", "");
        return int.`TryParse`(cleaned, out int qty) ? qty : 0;
    }

    private decimal `ParseAmount`(string text)
    {
        if (string.`IsNullOrEmpty`(text)) return 0;
        var cleaned = Regex.Replace(text, @"[^\d.]", "");
        return decimal.`TryParse`(cleaned, out decimal amt) ? amt : 0;
    }
}

// Data classes for structured invoice information
public class `InvoiceData`
{
    public string `InvoiceNumber` { get; set; }
    public `DateTime`? `InvoiceDate` { get; set; }
    public `DateTime`? `DueDate` { get; set; }
    public string `VendorName` { get; set; }
    public decimal Total { get; set; }
    public decimal Tax { get; set; }
    public List<`LineItem`> `LineItems` { get; set; }
    public List<string> `BarcodeValues` { get; set; }
}

public class `LineItem`
{
    public string Description { get; set; }
    public int Quantity { get; set; }
    public decimal `UnitPrice` { get; set; }
    public decimal Total { get; set; }
}
$vbLabelText   $csharpLabel

發票處理:從發票中提取特定數據

使用以下代碼提取特定發票數據,例如客戶發票號碼:

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);
    }
}
$vbLabelText   $csharpLabel

Visual Studio 偵錯控制台顯示已成功建立 PDF 文件,其中客戶發票編號 INV/2023/00039 已使用 IronOCR 提取,確認 OCR 流程已完成且無錯誤發票掃描

對於複雜的提取場景,請使用專門的 OCR 配置來最佳化您的發票類型。 OcrResult類別提供有關每個已識別元素的詳細信息,包括座標和用於驗證的置信度分數。

發票OCR API的主要優點是什麼?

IronOCR 的發票 OCR API 透過機器學習和電腦視覺技術改變了發票處理方式。 這項技術將發票文字轉換為機器可讀格式,簡化了資料擷取,以便於分析、整合和流程改進。 它為發票處理提供強大的自動化功能,提高準確性並優化應付帳款等工作流程。

IronOCR 利用優化的 Tesseract 結果,無需額外配置即可提供卓越的精度。 它支援多頁框架 TIFFPDF 文件以及所有流行的圖像格式。 從圖像中讀取條碼增加了另一個提取維度。

發票處理的主要優點:

1.節省時間:將數小時縮短至數秒 2.準確度:透過置信度評分最大限度地減少誤差 3.可擴展性:利用多執行緒處理數千個行程 4.整合:匯出為可搜尋的 PDF結構化格式 5.降低成本:降低營運成本

該程式庫部署靈活,可整合到現有系統中—本地部署、雲端部署或混合部署。 IronOCR 支援DockerAzureAWS ,可根據您的需求進行擴充。

生產環境可受益於 IronOCR 的許可選項,包括專門的支援和定期更新。 庫中的故障排除指南工程支援可確保順利實施。

請造訪主頁以了解更多關於IronOCR的資訊。 有關發票 OCR 的更多教程,請參閱這份詳細的發票 OCR 指南。 要了解如何使用電腦視覺技術識別發票字段,請查看這篇電腦視覺教學

常見問題解答

如何使用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。

坎納奧帕特·烏東潘特
軟體工程師
在成為軟體工程師之前,Kannapat 在日本北海道大學完成了環境資源專業的博士學位。在攻讀博士學位期間,他還加入了生物生產工程系下屬的車輛機器人實驗室。 2022 年,他憑藉 C# 技能加入了 Iron Software 的工程團隊,專注於 IronPDF 的開發。 Kannapat 非常珍惜這份工作,因為他可以直接向 IronPDF 大部分程式碼的編寫者學習。除了與同事學習之外,Kannapat 也享受在 Iron Software 工作的社交氛圍。工作之餘,Kannapat 通常會玩 PS5 遊戲或重溫《最後生還者》。