IRONSOFTWAREHOME
影片

從Patagames Tesseract.NET SDK遷移到| IronOCR

Kannaopat Udonpant
Kannapat Udonpant
Updated: 2026年8月1日

本指南引導 .NET 開發者從Patagames Tesseract.NET SDK完成遷移至IronOCR。 內容涵蓋機械 API 翻譯、驅動大多數遷移的跨平台部署解鎖,以及要求將生產 OCR 管道從僅限 Windows 的商業包裝移轉至可在 Windows、Linux、macOS、Docker、Azure 和 AWS 上運行的程式庫的實際程式碼更改。

為何從Patagames Tesseract.NET SDK遷移

大多數評估 Patagames 的團隊並不對 OCR 精確度不滿意。 他們遭遇了部署壁壘—一個 Linux 容器目標、一個雲端遷移專案,或一個在 Ubuntu 上的 CI 管道— 發現該僅限 Windows 的本機二進位不適合該平台。 這個單一限制驅動了其餘的遷移評估。

僅限 Windows 部署阻礙了現代 .NET 堆疊。 Patagames 為其 Tesseract 引擎包裝提供 Windows 本機二進位。 沒有 Linux x64、macOS 或 ARM 運行時封包。 OcrApi 類別在運行時載入 Windows DLL; 在其他任何作業系統上,應用程式無法啟動。 新增 System.Drawing.Bitmap 相依性,Microsoft 正式標記為不支持新的跨平台開發,該程式庫無法與每個雲供應商和容器協同管理器的預設部署模型相容。

為免費引擎支付商業費率,沒有跨平台存取。 Patagames 底層的 Tesseract 引擎是開源且免費的。 免費的社群包裝,如 tesseractocr,今天也提供預建的 Windows 二進位,這消除了 Patagames 歷史上提供的主要便利論點。 Patagames 的商業授權購買了一個較乾淨的 API 表面,但它並未新增預處理、PDF 支援、可搜尋的 PDF 輸出或跨平台部署— 這四個能力定義了 2026 年的一個完整的 OCR 程式庫。

不透明的定價使預算規劃不可能。 Patagames 不公布授權價格。 評估程式庫需要銷售聯繫,才能做出任何成本比較。IronOCR的定價從 $999 開始,為單一開發者的一年更新永久 Lite 授權。 團隊可以在沒有銷售過程的情況下評估成本與能力的差異。 請參閱 IronOCR 授權頁面 以獲取完整層級詳細資訊。

原始 Tesseract 變數從 API 洩漏。 設定頁面分割模式在 Patagames 中需要呼叫 api.SetVariable("tessedit_pageseg_mode", "3")— 一個原始字串基礎的 Tesseract 變數分派,無 IntelliSense,無編譯時檢查,無可發現性。 拼寫錯誤變數名稱,呼叫靜默不執行任何操作。IronOCR包裝每個 Tesseract 配置選項在 IronTesseract.Configuration 上使用強型別的屬性。

除了平面字串,沒有結構化輸出。 Patagames GetTextFromImage 返回單一字串。 無法存取單詞邊界,行群組,段落結構或每單詞的信心水準。 需要從表單中提取特定字段或逐字驗證 OCR 精度的應用程式在 Patagames API 上沒有可構建的基礎。

CI/CD 管道在 Linux 步驟中中斷。 現代 .NET 開發團隊在 Linux 上運行 CI— GitHub Actions、GitLab CI 和 Azure DevOps 全部預設為基於 Linux 的執行程式。 參考 Tesseract.Net.SDK 的專案要麼無法構建原生二進位引用,要麼在整合測試過程中運行時失敗。 每次測試運行需要一個特定於 Windows 的 CI 執行者或者一個完全模擬 OCR 層的解決方法。

根本問題

Patagames 目標僅限 Windows。 您的部署目標改變的瞬間,程式庫無法跟隨:

// Patagames: Windows DLL loads; fails on Linux container or macOS developer machine
using var api = OcrApi.Create();
api.Init(@"./tessdata", "eng"); // tessdata path — must be manually managed in every environment
using var bitmap = new Bitmap(imagePath); // System.Drawing — unsupported on non-Windows targets
return api.GetTextFromImage(bitmap);
C#
// IronOCR: same code runs on Windows, Linux, macOS, Docker, Azure, AWS
IronOcr.License.LicenseKey = "YOUR-LICENSE-KEY";
var text = new IronTesseract().Read(imagePath).Text;
C#

沒有 tessdata 目錄。 沒有本機 DLL 路徑。 沒有平台條件。 NuGet 相依性圖自動解析每個目標的正確運行時。

IronOCR對比 Patagames Tesseract.NET SDK:功能比較

下表涵蓋目前在生產中運行 Patagames 的團隊相關的能力。

功能Patagames Tesseract.NET SDKIronOCR
Windows 支援
Linux支持不是
macOS支持不是
Docker部署不是
Azure App Service不是
AWS Lambda不是
NuGet套件Tesseract.Net.SDKIronOcr
授權模式商業(聯繫取得價格)永久 ($999–$2,399,公開)
OCR 引擎Tesseract(開源)優化 Tesseract 5(捆綁)
Tessdata管理手動目錄帶 .traineddata 文件NuGet 語言套件
自動前處理None去偏、去噪、對比、二值化、銳化、縮放、膨脹、侵蝕
深度背景噪音去除None是 (DeepCleanBackgroundNoise())
本地PDF輸入否(需要外部渲染器)
多頁 TIFF 輸入有限是 (input.LoadImageFrames())
可搜尋的PDF輸出不是是 (result.SaveAsSearchablePdf())
hOCR 輸出不是
支持的語言Tesseract tessdata 文件125+ 透過NuGet包
多語言同時支援是(字串串接)是(強型別 OcrLanguage 枚舉)
基於區域的OCR不是是 (CropRectangle)
條碼識別不是
結構化輸出僅限平面字串頁、段落、行、詞、字元及坐標
每單字信心水準不是
頁面分割配置原始 SetVariable 字串呼叫強型別 Configuration.PageSegmentationMode
System.Drawing 相依性需要可選
執行緒安全標準 Tesseract 限制完整(為每個執行緒建立 IronTesseract
商業支持
NuGet 下載有限超過 530 萬

快速開始:從Patagames Tesseract.NET SDK遷移至 IronOCR

步驟1:替換NuGet包

移除 Patagames Tesseract.NET SDK:

dotnet remove package Tesseract.Net.SDK
SHELL

NuGet安裝IronOCR:

dotnet add package IronOcr

如需支援英語以外的語言,安裝相應的語言包:

dotnet add package IronOcr.Languages.French, IronOcr.Languages.German

步驟2:更新命名空間

將 Patagames 命名空間替換為IronOCR命名空間:

// Before (Patagames)
using Patagames.Ocr;
using Patagames.Ocr.Enums;
using System.Drawing;

// After (IronOCR)
using IronOcr;
C#

步驟3:初始化許可證

在應用程式啟動時新增授權初始化(在首次 IronTesseract 呼叫之前):

IronOcr.License.LicenseKey = "YOUR-LICENSE-KEY";

免費試用授權可在ironsoftware.com/C#/ocr/獲取,以開始遷移測試而不需購買。

程式碼遷移範例

批次資料夾處理

第一階段顯示單一影像提取。 生產 Patagames 部署通常在迴圈中初始化 OcrApi,在每次迭代上呼叫 api.Init()—這會在每個檔案上重新載入 tessdata 並重新初始化 Tesseract 引擎。此模式增加了每百份文件的初始化成本。

Patagames 方式:

// NuGet: Tesseract.Net.SDK
using Patagames.Ocr;
using System.Drawing;
using System.IO;

public class PatagamesBatchProcessor
{
    private const string TessDataPath = @"./tessdata";

    public Dictionary<string, string> ProcessFolder(string folderPath)
    {
        var results = new Dictionary<string, string>();

        foreach (var file in Directory.GetFiles(folderPath, "*.jpg"))
        {
            // OcrApi re-initialized per file — tessdata loaded each time
            using var api = OcrApi.Create();
            api.Init(TessDataPath, "eng");

            using var bitmap = new Bitmap(file);
            var text = api.GetTextFromImage(bitmap);

            results[Path.GetFileName(file)] = text;
        }

        return results;
    }
}
C#

IronOCR方法:

// NuGet: IronOcr
using IronOcr;
using System.IO;

IronOcr.License.LicenseKey = "YOUR-LICENSE-KEY";

public class IronOcrBatchProcessor
{
    public Dictionary<string, string> ProcessFolder(string folderPath)
    {
        var results = new Dictionary<string, string>();
        // Single engine instance — initialized once, reused across all files
        var ocr = new IronTesseract();

        foreach (var file in Directory.GetFiles(folderPath, "*.jpg"))
        {
            var result = ocr.Read(file);
            results[Path.GetFileName(file)] = result.Text;
        }

        return results;
    }
}
C#

IronOCR 的 IronTesseract 實例在呼叫間保持引擎狀態。 為整個批次重用一個實例,消除了每份文件的初始化負擔,並完全移除了 tessdata 路徑的相依性。 有關跨多個 CPU 核心的並行批次處理,請參閱多執行緒範例 — 每個執行緒建立一個 IronTesseract ,而不是共享單一實例。

頁面分割模式遷移

Patagames 通過一個原始 SetVariable 呼叫來公開頁面分割模式,帶字串鍵和轉為字串的整數值。 無 IntelliSense、枚舉驗證、文件提示位於呼叫端。一個數字決定了 Tesseract 是否將輸入視為單塊文字、一個列、一個單詞或一個單字元—拼錯變數名稱時沒有回饋。

Patagames 方式:

// NuGet: Tesseract.Net.SDK
using Patagames.Ocr;
using Patagames.Ocr.Enums;
using System.Drawing;

public string OcrSingleLineField(string imagePath)
{
    using var api = OcrApi.Create();
    api.Init(@"./tessdata", "eng");

    // Raw variable string — no IntelliSense, no validation
    // PageSegmentationMode.SingleLine == 7
    api.SetVariable("tessedit_pageseg_mode", "7");

    // Additional variable to suppress dictionary output
    api.SetVariable("tessedit_char_whitelist", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -.:/");

    using var bitmap = new Bitmap(imagePath);
    return api.GetTextFromImage(bitmap);
}
C#

IronOCR方法:

// NuGet: IronOcr
using IronOcr;

IronOcr.License.LicenseKey = "YOUR-LICENSE-KEY";

public string OcrSingleLineField(string imagePath)
{
    var ocr = new IronTesseract();

    // Strongly typed enum — discoverable through IntelliSense
    ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleLine;

    var result = ocr.Read(imagePath);
    return result.Text;
}
C#

每個 Patagames 通過 SetVariable 暴露的 Tesseract 配置選項在 IronTesseract.Configuration中都有直接的強型別對應。 遷移是原字串文字至命名枚舉值的機械替換。 有關完整配置表面的 IronTesseract API 參考,請參閱IronTesseract API 參考。 閱讀特定文件指南涵蓋了何時在不同文件型別上應用每個頁面分割模式。請參閱閱讀特定文件指南

結果迭代模式的替代方案

Patagames 從 GetTextFromImage 返回平面字串。 從 Patagames 輸出中提取單個單字、其邊界框或其信心水準需要基於返回的字串編寫解析器—或通過互操作直接存取底層 Tesseract 結果迭代器 API。這些方法都不可靠或可維護。IronOCR提供一個完整結構化 OcrResult,能夠本地存取每個層級的文件層次結構。

Patagames 方式:

// NuGet: Tesseract.Net.SDK
using Patagames.Ocr;
using System.Drawing;

public void ExtractWordsWithPositions(string imagePath)
{
    using var api = OcrApi.Create();
    api.Init(@"./tessdata", "eng");

    using var bitmap = new Bitmap(imagePath);
    //僅限平面字串— no word positions, no confidence, no line grouping
    var text = api.GetTextFromImage(bitmap);

    // Only option: split on whitespace and hope line breaks survive
    var words = text.Split(new[] { ' ', '\n', '\r' },
        StringSplitOptions.RemoveEmptyEntries);

    foreach (var word in words)
    {
        //不是X, Y, Width, Height — position information is lost
        Console.WriteLine(word);
    }
}
C#

IronOCR方法:

// NuGet: IronOcr
using IronOcr;

IronOcr.License.LicenseKey = "YOUR-LICENSE-KEY";

public void ExtractWordsWithPositions(string imagePath)
{
    var result = new IronTesseract().Read(imagePath);

    foreach (var page in result.Pages)
    {
        Console.WriteLine($"Page {page.PageNumber}: {page.Width}x{page.Height}px");

        foreach (var paragraph in page.Paragraphs)
        {
            Console.WriteLine($"  Paragraph at ({paragraph.X}, {paragraph.Y})");
            Console.WriteLine($"  Text: {paragraph.Text}");
        }

        foreach (var word in page.Words)
        {
            // Bounding box, confidence, and text for every word
            Console.WriteLine($"  Word: '{word.Text}' at ({word.X},{word.Y}) " +
                              $"size {word.Width}x{word.Height} " +
                              $"confidence {word.Confidence:F1}%");
        }
    }

    Console.WriteLine($"Overall confidence: {result.Confidence:F1}%");
}
C#

完整的 OcrResult 結構—頁面、段落、行、字詞和字元—消除了任何後處理解析器的需求。 單字座標能夠按位置提取字段,這是發票處理、表單 OCR 和表格提取的基礎。 有關完整層次結構及過濾低信心水字詞的信心水準指南,請參閱結構化結果指南信心水準指南

多頁 TIFF 處理

Patagames 接受一個 System.Drawing.Bitmap。 一個多幀 TIFF 包含多個嵌入的影像,但是 System.Drawing.Bitmap 未自動列舉幀 — 您必須使用 Image.SelectActiveFrame() 手動遍歷,並在迴圈中將每個幀位圖傳遞給 GetTextFromImage。幀列舉 API 不明顯,失敗時的錯誤消息不具描述性。

Patagames 方式:

// NuGet: Tesseract.Net.SDK
using Patagames.Ocr;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;

public string ProcessMultiPageTiff(string tiffPath)
{
    using var api = OcrApi.Create();
    api.Init(@"./tessdata", "eng");

    var sb = new StringBuilder();

    using var tiffImage = Image.FromFile(tiffPath);
    var frameCount = tiffImage.GetFrameCount(FrameDimension.Page);

    for (int i = 0; i < frameCount; i++)
    {
        // Manual frame selection — FrameDimension.Page required
        tiffImage.SelectActiveFrame(FrameDimension.Page, i);

        using var frameBitmap = new Bitmap(tiffImage);
        var pageText = api.GetTextFromImage(frameBitmap);
        sb.AppendLine(pageText);
    }

    return sb.ToString();
}
C#

IronOCR方法:

// NuGet: IronOcr
using IronOcr;

IronOcr.License.LicenseKey = "YOUR-LICENSE-KEY";

public string ProcessMultiPageTiff(string tiffPath)
{
    using var input = new OcrInput();
    // LoadImageFrames handles all frames automatically
    input.LoadImageFrames(tiffPath);

    // Optional: apply preprocessing to all frames at once
    input.Deskew();
    input.DeNoise();

    var result = new IronTesseract().Read(input);

    // Per-page access if needed
    foreach (var page in result.Pages)
    {
        Console.WriteLine($"Page {page.PageNumber}: {page.Words.Length} words");
    }

    return result.Text;
}
C#

OcrInput.LoadImageFrames() 內部處理幀列舉,並對管道中的每個幀進行預處理。System.Drawing 幀選擇儀式完全消失。 請參閱TIFF 和 GIF 輸入指南以獲取更多選項,包括僅需要特定頁面時的單幀選擇。

無需要外部渲染器的 PDF 輸入

Patagames 沒有本機 PDF 支援。 基於 Patagames 的 PDF OCR 管道需要外部 PDF 渲染程式庫(如 PdfiumViewer、iText 或 PDFSharp)將每頁轉換為 Bitmap,然後再傳遞給 GetTextFromImage。 該外部相依性增加了包裝管理開銷、一個獨立的授權考慮以及一個次要的故障點。 渲染質量也因不同而異,影響 Tesseract 引擎之外的 OCR 精度。

Patagames 方式:

// NuGet: Tesseract.Net.SDK + PdfiumViewer (external dependency)
using Patagames.Ocr;
using PdfiumViewer; // separate NuGet package required
using System.Drawing;
using System.Text;

public string OcrPdfDocument(string pdfPath)
{
    using var api = OcrApi.Create();
    api.Init(@"./tessdata", "eng");

    var sb = new StringBuilder();

    // External renderer required — Patagames has no PDF support
    using var pdfDoc = PdfDocument.Load(pdfPath);

    for (int page = 0; page < pdfDoc.PageCount; page++)
    {
        // Render at 300 DPI for acceptable OCR accuracy
        using var img = pdfDoc.Render(page, 300, 300, false);
        using var bitmap = new Bitmap(img);

        var pageText = api.GetTextFromImage(bitmap);
        sb.AppendLine(pageText);
    }

    return sb.ToString();
}
C#

IronOCR方法:

// NuGet: IronOcr only — no external PDF renderer
using IronOcr;

IronOcr.License.LicenseKey = "YOUR-LICENSE-KEY";

public string OcrPdfDocument(string pdfPath)
{
    using var input = new OcrInput();
    input.LoadPdf(pdfPath);

    // Preprocessing applies to every page in one call
    input.Deskew();

    var ocr = new IronTesseract();
    var result = ocr.Read(input);

    // Full per-page structured access
    foreach (var page in result.Pages)
    {
        Console.WriteLine($"Page {page.PageNumber}: {page.Paragraphs.Length} paragraphs");
    }

    return result.Text;
}
C#

一個 NuGet 包代替了兩個。 過程中消失。 PDF 輸入指南 涵蓋單頁、多頁和受密碼保護的 PDF。 有關可搜尋的 PDF 輸出工作流程—從掃描的 PDF 生成可透過 Ctrl+F 搜索的文件—請參閱可搜尋的 PDF 指南可搜尋的 PDF 範例以查看五行程式碼中的完整管道。

Patagames Tesseract.NET SDK API 至IronOCR映射參考

Patagames Tesseract.NET SDKIronOCR 等效
Tesseract.Net.SDK (NuGet 包)IronOcr (NuGet 包)
Patagames.Ocr (命名空間)IronOcr (命名空間)
Patagames.Ocr.Enums (命名空間)IronOcr (命名空間)
OcrApi.Create()new IronTesseract()
api.Init(tessDataPath, "eng")ocr.Language = OcrLanguage.English (無路徑)
api.Init(path, "eng+fra+deu")ocr.Language = OcrLanguage.English + OcrLanguage.French + OcrLanguage.German
api.GetTextFromImage(bitmap)ocr.Read(imagePath).Text
api.SetVariable("tessedit_pageseg_mode", "7")ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleLine
api.SetVariable(key, value) (任何原始變數)ocr.Configuration.[TypedProperty]
new Bitmap(imagePath) (輸入準備)input.LoadImage(imagePath)
OcrBitmap.FromFile(path)input.LoadImage(path)
無多幀 TIFF 支援input.LoadImageFrames(tiffPath)
無 PDF 輸入input.LoadPdf(pdfPath)ocr.Read(pdfPath)
無可搜尋 PDFresult.SaveAsSearchablePdf("output.pdf")
無前處理input.Deskew(), input.DeNoise(), input.Contrast(), input.Binarize()
無區域 OCRinput.LoadImage(path, new CropRectangle(x, y, w, h))
無條碼讀取ocr.Configuration.ReadBarCodes = true
僅限平面字串結果result.Pages, result.Lines, result.Words, result.Paragraphs
無每單字信巡result.Words[i].Confidence, result.Confidence
PageSegmentationMode 枚舉TesseractPageSegmentationMode 枚舉
無 hOCR 輸出結果 .ToHOcrString() 輸出
僅限 Windows x64/x86Windows、Linux、macOS、Docker、Azure、AWS

常見的遷移問題与解決方案

問題 1:新環境中缺少 Tessdata 目錄

Patagames: 如果缺少 tessdata 目錄或 eng.traineddata 文件,api.Init(@"./tessdata", "eng") 呼叫在運行時間失敗。 在容器化環境中,這是一個部署時間故障,沒有編譯時警告。 部署到 Docker 的團隊經常在影像已經推送之後才發現這一點。

**解決方案:**IronOCR完全移除 tessdata 目錄的概念。 安裝語言資料作為 NuGet 包:

dotnet add package IronOcr.Languages.English

語言資料在編譯時解析,並自動包含在 dotnet publish 輸出中。 沒有路徑錯誤,沒有語言檔案的部署清單項目。

問題 2:System.Drawing.Bitmap 在 Linux 上失敗

Patagames: 除非在 Linux 上安裝有關系統包,否則 System.Drawing.Bitmap 構造函式在 Linux 上引發 TypeInitializationExceptionPlatformNotSupportedException。 即使在 libgdiplus 存在的情況下,行為也因分發而異。 Microsoft 明確建議在新開發中不要在非 Windows 平台上使用 System.Drawing

**解決方案:**IronOCR直接接受檔案路徑、位元組陣列和串流。 不需要 System.Drawing 相依性:

// Replace this pattern:
using var bitmap = new Bitmap(imagePath); // fails without libgdiplus on Linux
api.GetTextFromImage(bitmap);

// With:
var result = new IronTesseract().Read(imagePath); // no System.Drawing required
C#

請參閱影像輸入指南,以了解包括位元組陣列和串流在內的所有支援的輸入型別。

問題 3:靜默 SetVariable 失敗

Patagames: api.SetVariable("tessedit_pageseg_mode", someValue) 返回 bool,但大多數呼叫者丟棄返回值。 當變數名稱被拼錯或傳遞了不支援的值時,Tesseract 靜默應用預設值並繼續。 結果的準確性下降很難追溯到配置呼叫。

**解決方案:**IronOCR的配置屬性為強型別。 無效的分派會產生一個編譯器錯誤,而不是靜默運行時預設:

// Compile-time safety — no silent failures
var ocr = new IronTesseract();
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock;
ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5; // also strongly typed
C#

問題 4:OcrApi 在迴圈中初始化

Patagames: 在處理迴圈中初始化 OcrApi 的團隊,在每次迭代上都會產生 tessdata 載入的開銷。 從執行緒隔離的角度來看,OcrApi.Create()api.Init()foreach中是正確的模式,但在處理數百份文件時非常昂貴。

解決方案: 每個執行緒建立一個 IronTesseract,並在指定給該執行緒的所有文件中重複使用。 此實例在 .Read() 呼叫之間是無狀態的:

// One instance, many reads — engine initialized once
var ocr = new IronTesseract();
ocr.Language = OcrLanguage.English;

foreach (var file in imageFiles)
{
    var text = ocr.Read(file).Text;
    ProcessText(text);
}
C#

對於並行批次工作負載,為每個任務建立一個實例。 請參閱速度優化指南以獲取吞吐量調整選項,包括 IronTesseract.Configuration.TesseractVersion 和閱讀速度預設。

問題 5:沒有 Linux Docker 基底映像可以運行

Patagames: 沒有相容於 Linux 的 Patagames 二進位。 在 Linux Docker 容器中運行基於 Patagames 的應用程式的任何嘗試都會失敗。 唯一的解決方法是使用基於 Windows 的容器(FROM mcr.microsoft.com/windows/servercore),它顯著更大、拉取速度較慢,並且與大多數使用 Linux 節點池的 Kubernetes 配置不相容。

**解決方案:**IronOCR支援標準的 Linux 基底映像。 Docker 部署指南涵蓋了確切的 Dockerfile 配置:

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/publish .
#IronOCRresolves the Linux native runtime from NuGet automatically
ENTRYPOINT ["dotnet", "MyApp.dll"]
Text

不需要 Windows 容器。 不需要單獨的二進位分配。 相同的 Docker 映像可在任何基於 Linux 的容器主機上運行。

問題 6:PDF OCR 需要兩個 NuGet 包

Patagames: 向 Patagames 應用程式中新增 PDF OCR 需要 PDF 渲染的第二個 NuGet 包(如 PdfiumViewer、iTextSharp.LGPLv2.Core 或類似)。 每個都新增了其自己的授權條款、更新頻率和潛在的相容性問題。 當 PDF 渲染器版本與 Patagames 版本衝突時,雙方團隊必須參與解決它。

**解決方案:**IronOCR原生處理 PDF 輸入,無需第二個包。 完全移除 PDF 渲染器的相依性:

# Remove the PDF rendering shim
dotnet remove package PdfiumViewer

#IronOCRhandles PDF natively
var result = new IronTesseract().Read("document.pdf");
SHELL

Patagames Tesseract.NET SDK遷移檢查清單

遷移前

在開始之前審計程式碼庫以識別所有 Patagames 參考:

# Find all files using Patagames namespaces
grep -r "Patagames.Ocr" --include="*.cs" . -l

# Find all OcrApi usage patterns
grep -r "OcrApi\|GetTextFromImage\|api\.Init\|SetVariable" --include="*.cs" .

# Find tessdata path references
grep -r "tessdata\|TessDataPath\|traineddata" --include="*.cs" .

# Find System.Drawing.Bitmap usage tied to OCR
grep -r "new Bitmap\|System\.Drawing" --include="*.cs" . -l

# Find any PDF rendering libraries used to feed Patagames
grep -r "PdfiumViewer\|iTextSharp\|PdfSharp" --include="*.csproj" .
SHELL

文件:OcrApi.Create() 呼叫位置的總數、不同 api.Init() 語言配置的數量、每個部署環境中的 tessdata 目錄位置,以及 System.DrawingImageSharp 中為封裝 Patagames 呼調整的任何預處理程式碼。

程式碼遷移

  1. 從所有專案中移除 Tesseract.Net.SDK NuGet 包參考。
  2. 移除任何僅用於提供給 Patagames 的 PDF 渲染 NuGet 包(如 PdfiumViewer、iText 等)。
  3. 安裝 IronOcr NuGet 包。
  4. 安裝 IronOcr.Languages.English 和任何其他需要的語言包。
  5. 在應用程式啟動時新增 IronOcr.License.LicenseKey = "YOUR-LICENSE-KEY"
  6. using IronOcr; 替換 using Patagames.Ocr;using Patagames.Ocr.Enums;
  7. 將每條 OcrApi.Create() + api.Init(path, lang) 區塊替換為 new IronTesseract() + ocr.Language = OcrLanguage.[Language]
  8. ocr.Read(imagePath).Text 替換每次 api.GetTextFromImage(bitmap) 呼叫(移除 Bitmap 建構器)。
  9. 將每次 api.SetVariable("tessedit_pageseg_mode", value) 呼叫替換為 ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.[Value] 型別。
  10. 移除所有僅為傳遞影像給 Patagames 而存在的 System.Drawing.Bitmap 實例化。
  11. input.LoadPdf(pdfPath) 替換 PDF 渲染迴圈(如果存在)。
  12. 將使用 Image.SelectActiveFrame() 的多幀 TIFF 迴圈改為 input.LoadImageFrames(tiffPath)
  13. 用相應的 OcrInput 過濾器呼叫替換任何自訂預處理程式碼(System.Drawing 大小調整、對比、門檻)。
  14. 從所有部署清單、Dockerfile 和 CI 複製步驟中移除 tessdata 目錄。
  15. 更新整合測試以在 Linux CI 執行者(如 GitHub Actions ubuntu-latest 等)上運行,以驗證跨平台行為。

遷移後

  • 在 Linux(不僅在 Windows)上運行完整測試套件,以確認跨平台部署解鎖是否正常運作。
  • 驗證 OCR 準確性與 Patagames 基準在相同測試影像集上的結果相等或更好。
  • 確認使用 OcrLanguage 枚舉方法的多語言文件產生正確輸出。
  • 無需外部渲染程式庫,直接測試 PDF 輸入,並將輸出準確性與舊渲染影像路徑相比較。
  • 驗證多幀 TIFF 處理產生的頁數與文字內容和之前幀枚舉迴圈相同。
  • 確認部署物件中缺少 tessdata 目錄,且沒有運行時路徑錯誤發生。
  • 針對 linux/amd64 運行 Docker 構建,並在容器中至少執行一次 OCR 呼叫。
  • 驗證 CI 管道(GitHub Actions,GitLab CI,Azure DevOps)在其預設的 Linux 執行器上成功完成。
  • 驗證結果中是否有可用的信心水準,以及任何基於信心水準的過濾邏輯是否正常工作。
  • 確認授權金鑰初始化在生產啟動程式碼中建立 IronTesseract 實例之前運行。

遷移至IronOCR的主要好處

無需程式碼更改即可跨平台部署。 遷移後,同一二進位檔可在 Windows Server、Ubuntu Docker 容器、macOS 開發機、Azure App Service on Linux 和 AWS Lambda 上運行。 沒有平台條件句,沒有運行時識別標識標誌,沒有針對每個作業系統的單獨部署工件。 以前被僅限 Windows OCR 程式庫擋住的雲遷移變為標準容器部署。 LinuxDockerAzureAWS 部署指南涵蓋了每個目標的生產配置。

tessdata 管理從運營消失。 tessdata 目錄——其位置、內容、在每個環境中的存在不再是運營考量。 語言資料是 NuGet 相依性,在編譯時解析。自動出現在 dotnet publish 輸出中。 新增新語言時,無需更新部署運行手冊,tessdata 文件變更時,無需無效 Docker 層,且不會有缺少 tessdata 的生產事件需要調查。

結構化輸出取代字串解析。 先前從 GetTextFromImage 解析平面字串以提取字段、驗證內容或計算信心水準的應用程式,現在直接從 OcrResult 存取這些資料。 單字座標、行邊界、段落群組和每單字信心水準是頭等屬性。 按邊界框提取字段——發票處理和表單 OCR 的基礎——是一個直接的 CropRectangle 呼叫,而非脆弱的子字串搜索。

內建預處理取代自訂影像管道。 任何編寫來補償 Patagames 缺乏內建過濾器的預處理程式碼,可以用 OcrInput 方法呼叫替代。 去偏、去噪、對比增強、二值化和解析度規範化都是單行操作。 花費 20-40 小時構建和調整 System.Drawing 預處理管道的團隊,可以用五個方法呼叫替代它,並將該維護努力重定向到其他地方。 請參閱預處理功能概覽以獲取完整的過濾器目錄。

本機 PDF 支援移除了一個相依性類別。 僅用於橋接 Patagames PDF 空隙的 PDF 渲染程式庫已被消除。 以前需要在 Tesseract.Net.SDK、PDF 渲染器及其共享的 System.Drawing 相依性三個包之間協調更新的生產 OCR 系統,現在只有一個沒有橋接相依性的 OCR 包。 包括密碼保護和多頁文件的 PDF 輸入是一級輸入型別。 對於合規和記錄管理用途,result.SaveAsSearchablePdf() 在不需額外庫的單一呼中生成文字層 PDF 輸出。

**透明定價和商業支援。**IronOCR的 $999 永久 Lite 授權覆蓋一位開發人員和一個部署地點,並包括一年更新。 定價為公眾可見,層級結構明確,提供商業支援而無需企業合同。 為 Windows 版 Tesseract 包裝付費的 Patagames 使用者獲得跨平台部署、預處理、PDF 支援,及超過 125 種語言—同時採用成本在評估完成前已知的定價模型。 請參閱 IronOCR 授權,以獲取完整層級詳情,以及IronOCR 產品頁面以獲取免費試用授權。

請注意: PDFium, PDFSharp, Tesseract, 和 iText 是其各自所有者的註冊商標。 本網站未與 Chromium Project、Google、empira Software GmbH 或 iText Group 有關聯,亦未經其認可或贊助。所有產品名稱、標誌和品牌均屬其各自所有者的財產。 比較僅供資訊用途,並反映撰寫時獲得的公開資訊。

相關文章

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
獲取您的無義務諮詢
填寫以下表格或發送電子郵件至sales@ironsoftware.com
您的詳細資訊將始終保密。
被全球數百萬工程師信任
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立