与其他组件比较

IronOCR与PDFTRON OCR的比较

发布 2022年九月5日
分享:

OCR 是 "光学字符识别 "的缩写。这是将纸质文件或图像转换为可读文本的过程。有多种方法可以做到这一点,如扫描或通过键盘手动输入。这样做的目的是将任何扫描文件、PDF 文件或手写文件转换为原始文本格式。在刑事案件中,如果文件损坏严重,无法进行人工转录,但可以通过 OCR 软件进行扫描和解释,那么这一过程就显得非常有价值。

随着技术的进步和数字工具的普及,OCR 也被应用于其他领域,如 Google Docs 等应用程序上的文档转换,以及学术界和商业界。OCR 有两种主要类型:"静态 "和 "动态"。最常见的是静态 OCR,即一次性扫描整个文档。而动态 OCR 则是一行一行地扫描,可以处理表格数据等更复杂的布局。

本文将讨论两种最流行的 OCR 和 PDF 应用程序和文档库之间的比较。它们是

  • PDFTron OCR
  • IronOCR

1.0 简介

1.1 PDFTron OCR 简介和功能

要在 PDFTron SDK 中使用 OCR,我们必须安装一个单独的 OCR 模块附加工具。这有助于 SDK 检测文档中的文本。它可以使文本可选择和可搜索。PDFTron SDK 支持多达 100 种语言。PDFTron OCR 引擎由 Tesseract 的开源 LSTM 神经网络提供支持。PDFTron OCR 支持多种图像格式的文本检测。只包含光栅图像的 PDF 文件也可用于 OCR,输出质量取决于输入图像。OCR 的最佳图像是分辨率为 300 DPI 的灰度图像。

PDFTron OCR 的功能

  • 在打印文档中搜索图像
  • 将简单的 PDF 转换为可搜索的 PDF。
  • 检测商业文档中的重要信息
  • 让图书扫描更轻松
  • 从车辆图像中检测车辆编号。
  • 帮助视障用户
  • 使用 OCR,可轻松地从文件中为多个文档输入数据。
  • 轻松将名片信息转入联系人数据列表。

1.2 IronOCR &##8212; 简介和功能

Iron Software 为软件工程师提供 IronOCR for .NET,用于在 .NET 应用程序和网站中读取照片和 PDF 中的文本内容。该软件可帮助扫描照片中的文本和条形码,支持多种全球语言,并可输出纯文本或结构化数据。Iron Software 的 OCR Library 可用于 Web、控制台、MVC 和众多 .NET 桌面应用程序。在商业部署中,除了购买许可证外,还可获得开发团队的直接帮助。

  • IronOCR 使用最新的 Tesseract 5 引擎,可读取任何 PDF 格式的文本、二维码和条形码。使用该库将 OCR 添加到桌面、网络应用程序和控制台,可确保快速集成。
  • IronOCR 支持 127 种国际语言。它还支持自定义语言和单词表。
  • IronOCR 可读取 20 多种条形码和 QR 码格式。
  • 支持多页 GIF 和 TIFF 图像格式。
  • 纠正低质量扫描和图像。
  • 支持多线程。可同时执行一个或多个进程。
  • IronOCR 可提供页面、段落、行、字、字符等结构化数据输出。
  • IronOCR 支持 Windows、Linux、macOS 等操作系统。

2.在 Visual Studio 中创建新项目

打开 Visual Studio,找到文件菜单。选择新建项目,然后选择控制台应用程序。本文将使用控制台应用程序生成 PDF 文档。

在相应的文本框中输入项目名称并选择文件路径。然后,单击 Create 按钮。同时,选择所需的 .NET Framework。

现在,Visual Studio 项目将为所选应用程序生成结构。

Visual Studio 现在将生成项目结构。如果您选择了 Windows、控制台和 Web 应用程序,program.cs 文件将打开,您可以输入代码并构建/运行应用程序。

下一步,我们需要添加库来测试代码。

3.0 安装

3.1 安装 PDFtron OCR

PDFTron OCR 的安装是手动完成的,可以从以下地址下载压缩包 链接.解压缩并与项目一起配置。本指南将帮助您使用 PDFTron SDK 的免费集成试用版,在使用 Windows 的 .NET Framework 应用程序中执行 PDFTron 示例。免费试用包括解决方案工程师的支持和无限次试用。

先决条件

Visual Studio: 确保.NET 桌面开发.NET Framework 4.5.1+ 开发工具工作负载是您安装的一部分。本指南将使用 Visual Studio 2017 和 PDFTron 的 Windows 版 C# .NET PDF 库。使用此链接下载该库、 .NET PDF SDK 下载.

初始设置

从 .zip 文件中解压文件夹。本指南中使用 PDFNET_BASE 来选择进入解压缩文件夹的路径。

PDFNET_BASE = path/to/extraction/folder/PDFNetDotNet4/
PDFNET_BASE = path/to/extraction/folder/PDFNetDotNet4/
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'PDFNET_BASE = path/@to/extraction/folder/PDFNetDotNet4/
VB   C#

运行样本

导航至提取内容的位置。找到并进入样本文件夹 (PDFNET_BASE/Samples).该文件夹包含 PDFTron SDK 所支持功能的大量示例代码。

1.在 Visual Studio 中打开 Samples_20XX.sln。选择适合您的 Visual Studio 安装的版本。

2.选择示例代码并 将其设置为启动项目 为解决方案。

3.运行项目。

集成到您的应用程序中

这就是所谓的 "PDFTron Hello World "应用程序。只要能打开、保存和关闭 PDF 文档,就能轻松集成 PDFTron SDK 的其他部分。

1.在 Visual Studio 中,用你喜欢的语言创建一个 .NET Framework 控制台应用程序项目。您可以在 Visual C# 或 Visual Basic 类别下找到它们。

2.导航进入项目文件夹。默认情况下,路径应类似于C:/Users/User_Name/source/repos/myApp

3.从 PDFNET_BASE 到项目文件夹 (该文件夹将包含您的 .csproj 或 .vbproj 文件)复制 Lib 文件夹。

4.找到右侧的 "解决方案资源管理器"。右键单击 "引用",选择 "添加引用 "选项。这将打开一个 "参考资料管理器 "对话框。

5.在对话框底部选择 "浏览"。找到复制的 Lib 文件夹,将 PDFNetLoader.dll 添加到引用中

6.此外,从 x86 文件夹中添加合适版本的 PDFNet.dll 作为另一个引用 (path/to/your/project/folder/Lib/PDFNet/x86/PDFNet.dll).这将确保应用程序同时在 32 位和 64 位操作系统上运行。

7.单击 PDFNet.dll。确保将其复制本地属性设置为假。

3.2 安装 IronOCR

IronOCR 库有四种安装方式。

它们是

  • 使用 Visual Studio。
  • 使用 Visual Studio 命令行
  • 从 NuGet 网站直接下载。
  • 从 IronPDF 网站直接下载。

3.2.1 使用 Visual Studio

Visual Studio 软件提供了 NuGet 软件包管理器选项,可直接将软件包安装到解决方案中。截图演示了如何打开 NuGet 包管理器。

这将提供一个搜索框,显示 NuGet 网站上的软件包列表。在软件包管理器中,我们需要搜索关键字 "IronOCR",如下截图所示:

从上图中,我们可以看到相关搜索结果的列表。要将软件包安装到解决方案中,我们必须选择所需的选项。

3.2.2 使用 Visual Studio 命令行

  • 在 Visual Studio 中转到工具-> NuGet软件包管理器 -> 软件包管理器控制台
  • 在软件包管理器控制台选项卡中输入随后的代码片段。

安装软件包 IronOcr

现在,软件包将直接安装到当前项目中,然后就可以使用了。

3.2.3 从 NuGet 网站直接下载

对于第三种方法,我们可以直接从网站下载 NuGet 软件包

  • 导航至 链接.
  • 从右侧菜单中,确保选择下载软件包选项。
  • 双击下载的软件包。软件包将自动安装。
  • 接下来,重新加载解决方案并开始在项目中使用。

3.2.4 从 IronOCR 网站直接下载

您可以点击以下链接直接从网站下载最新软件包 链接.下载最新软件包后,请按照提供的说明将软件包添加到项目中。

  • 在解决方案窗口中右键单击项目。
  • 选择 "选项参考 "浏览下载参考的位置。

  • 然后单击 "确定 "添加引用。

4.0 OCR 图像

IronOCR 和 PDFtron OCR 都有 OCR 技术,可将图像转换为文本搜索。

4.1 使用 PDFTron

将 PDF 转换为 DOCX、DOC、HTML、SVG、TIFF、PNG、JPEG、XPS、EPUB、TXT 和许多其他格式。


PDFDoc doc = new PDFDoc(文件名);

// 将 PDF 文档转换为 SVG

Convert.ToSvg(doc, output_filename + ".svg");

// 将 PDF 文档转换为 XPS

Convert.ToXps(filename, output_filename + ".xps");

// 将 PDF 文档转换为多页 TIFF 文件

Convert.TiffOutputOptions tiff_options = new Convert.TiffOutputOptions();

tiff_options.SetDPI(200);

tiff_options.SetDither(真);

tiff_options.SetMono(真);

Convert.ToTiff(文件名, output_filename + ".tiff", tiff_options);

// 将 PDF 转换为 XOD

Convert.ToXod(filename, output_filename + ".xod");

// 将 PDF 转换为 HTML

Convert.ToHtml(文件名, output_filename + ".html");

PDFDoc doc = new PDFDoc(文件名);

// 将 PDF 文档转换为 SVG

Convert.ToSvg(doc, output_filename + ".svg");

// 将 PDF 文档转换为 XPS

Convert.ToXps(filename, output_filename + ".xps");

// 将 PDF 文档转换为多页 TIFF 文件

Convert.TiffOutputOptions tiff_options = new Convert.TiffOutputOptions();

tiff_options.SetDPI(200);

tiff_options.SetDither(真);

tiff_options.SetMono(真);

Convert.ToTiff(文件名, output_filename + ".tiff", tiff_options);

// 将 PDF 转换为 XOD

Convert.ToXod(filename, output_filename + ".xod");

// 将 PDF 转换为 HTML

Convert.ToHtml(文件名, output_filename + ".html");
Dim doc As New PDFDoc(文件名)

' 将 PDF 文档转换为 SVG

Convert.ToSvg(doc, output_filename & ".svg")

' 将 PDF 文档转换为 XPS

Convert.ToXps(filename, output_filename & ".xps")

' 将 PDF 文档转换为多页 TIFF 文件

Dim tiff_options As New Convert.TiffOutputOptions()

tiff_options.SetDPI(200)

tiff_options.SetDither(真)

tiff_options.SetMono(真)

Convert.ToTiff(文件名, output_filename & ".tiff", tiff_options)

' 将 PDF 转换为 XOD

Convert.ToXod(filename, output_filename & ".xod")

' 将 PDF 转换为 HTML

Convert.ToHtml(文件名, output_filename & ".html")
VB   C#

4.2 使用 IronOCR

var Ocr = new IronTesseract(); // nothing to configure
Ocr.Language = OcrLanguage.EnglishBest;
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
using (var Input = new OcrInput())
{
    Input.AddImage(@"3.png");
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
    Console.ReadKey();
}
var Ocr = new IronTesseract(); // nothing to configure
Ocr.Language = OcrLanguage.EnglishBest;
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
using (var Input = new OcrInput())
{
    Input.AddImage(@"3.png");
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
    Console.ReadKey();
}
Dim Ocr = New IronTesseract() ' nothing to configure
Ocr.Language = OcrLanguage.EnglishBest
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5
Using Input = New OcrInput()
	Input.AddImage("3.png")
	Dim Result = Ocr.Read(Input)
	Console.WriteLine(Result.Text)
	Console.ReadKey()
End Using
VB   C#

上面演示的是使用 Tesseract 5 API 将图像文件转换为文本的过程。上述代码用于为 Iron Tesseract 创建一个对象。此外,为确保我们能添加一个或多个图片文件,我们创建了一个 OcrInput 对象,该对象需要可用的图片路径。在 Iron Tesseract 对象中,函数 "Read "可用于通过解析图片文件获取图片,并将生成的结果提取到 OCR 结果中。它能够从照片中提取文本并将其转换为字符串。

在此过程中,可以使用 "AddMultiFrameTiff"方法来添加多帧图像。Tesseract 库会读取图像中的每一帧,并将其视为不同的页面。图像的每一帧都会被读取,然后再读取下一帧,直到每一帧都被成功扫描。此方法只支持 TIFF 图像格式。

将数据成功转换为可编辑文本的结果显示在上图中,这是 IronOCR 精确度的结果。

5.0 OCR PDF 文件

IronOCR 和 PDFTron OCR 可将 PDF 文件转换为可编辑文本。 PDFTron OCR 为用户提供了一系列选项,如保存页面、编辑图像、识别页面等。此外,它还可以提供文档、文本、HTML 格式等保存选项。IronOCR 还允许我们将转换后的 OCR 文件保存为 HTML、文本、PDF 等格式。

5.1 使用 PDFTron OCR

完整的示例代码展示了如何使用 PDFTron OCR 在 PDF、XPS、EMF、SVG、TIFF、PNG、JPEG 和其他图像格式之间进行直接、高质量的转换。

// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;

// The following code showcases the conversion of documents to formats // such as SVG, PDF, EMF, or XPS.

namespace ConvertTestCS
{
    class Testfile
    {
        public string inputFile, outputFile;
        public bool requiresWindowsPlatform;
        public Testfile(string inFile, string outFile, bool requiresWindowsPlatform_)
        {
            inputFile = inFile;
            outputFile = outFile;
            requiresWindowsPlatform = requiresWindowsPlatform_;
        }
    };

    class Class1
    {
        private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
        static Class1() {}

        // Relative path to the folder containing test files.
        const string inputPath = "../../../../TestFiles/";
        const string outputPath = "../../../../TestFiles/Output/";

        static bool ConvertSpecificFormats()
        {
            bool err = false;
            try
            {
                using (PDFDoc pdfdoc = new PDFDoc())
                {
                    Console.WriteLine("Converting from XPS");
                    pdftron.PDF.Convert.FromXps(pdfdoc, inputPath + "simple-xps.xps");
                    pdfdoc.Save(outputPath + "xps2pdf v2.pdf", SDFDoc.SaveOptions.e_remove_unused);
                    Console.WriteLine("Saved xps2pdf v2.pdf");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

    /////////////////////////////////////////////
    if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
                try
                {
                    using (PDFDoc pdfdoc = new PDFDoc())
                    {
                        Console.WriteLine("Converting from EMF");
                        pdftron.PDF.Convert.FromEmf(pdfdoc, inputPath + "simple-emf.emf");
                        pdfdoc.Save(outputPath + "emf2pdf v2.pdf", SDFDoc.SaveOptions.e_remove_unused);
                        Console.WriteLine("Saved emf2pdf v2.pdf");
                    }
                }
                catch (PDFNetException e)
                {
                    Console.WriteLine(e.Message);
                    err = true;
                }
            }

        ///////////////////////////////////////////
            try
            {
                using (PDFDoc pdfdoc = new PDFDoc())
                {
                    // Add a dictionary
                    ObjSet set = new ObjSet();
                    Obj options = set.CreateDict();

                    // Put options
                    options.PutNumber("FontSize", 15);
                    options.PutBool("UseSourceCodeFormatting", true);
                    options.PutNumber("PageWidth", 12);
                    options.PutNumber("PageHeight", 6);

                    // Convert from .txt file
                    Console.WriteLine("Converting from txt");
                    pdftron.PDF.Convert.FromText(pdfdoc, inputPath + "simple-text.txt", options);
                    pdfdoc.Save(outputPath + "simple-text.pdf", SDFDoc.SaveOptions.e_remove_unused);
                    Console.WriteLine("Saved simple-text.pdf");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

    ///////////////////////////////////////////
            try
            {
                using (PDFDoc pdfdoc = new PDFDoc(inputPath + "newsletter.pdf"))
                {
                    // Convert PDF document to SVG
                    Console.WriteLine("Converting pdfdoc to SVG");
                    pdftron.PDF.Convert.ToSvg(pdfdoc, outputPath + "pdf2svg v2.svg");
                    Console.WriteLine("Saved pdf2svg v2.svg");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

    /////////////////////////////////////////////////
            try
            {
                // Convert PNG image to XPS
                Console.WriteLine("Converting PNG to XPS");
                pdftron.PDF.Convert.ToXps(inputPath + "butterfly.png", outputPath + "butterfly.xps");
                Console.WriteLine("Saved butterfly.xps");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }
    ///////////////////////////////////////////
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                try
                {
                    // Convert MSWord document to XPS
                    Console.WriteLine("Converting DOCX to XPS");
                    pdftron.PDF.Convert.ToXps(inputPath + "simple-word_2007.docx", outputPath + "simple-word_2007.xps");
                    Console.WriteLine("Saved simple-word_2007.xps");
                }
                catch (PDFNetException e)
                {
                    Console.WriteLine(e.Message);
                    err = true;
                }
            }
            ////////////////////////////////////////////////////////////////////
            try
            {
                // Convert PDF document to XPS
                Console.WriteLine("Converting PDF to XPS");
                pdftron.PDF.Convert.ToXps(inputPath + "newsletter.pdf", outputPath + "newsletter.xps");
                Console.WriteLine("Saved newsletter.xps");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

            //////////////////////////////////////////////////////////////////////
            try
            {
                // Convert PDF document to HTML
                Console.WriteLine("Converting PDF to HTML");
                pdftron.PDF.Convert.ToHtml(inputPath + "newsletter.pdf", outputPath + "newsletter");
                Console.WriteLine("Saved newsletter as HTML");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

            //////////////////////////////////////////////////////////////////////
            try
            {
                // Convert PDF document to EPUB
                Console.WriteLine("Converting PDF to EPUB");
                pdftron.PDF.Convert.ToEpub(inputPath + "newsletter.pdf", outputPath + "newsletter.epub");
                Console.WriteLine("Saved newsletter.epub");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

            /////////////////////////////////////////////////////////////////////
            try
            {
                // Convert PDF document to multipage TIFF
                Console.WriteLine("Converting PDF to multipage TIFF");
                pdftron.PDF.Convert.TiffOutputOptions tiff_options = new pdftron.PDF.Convert.TiffOutputOptions();
                tiff_options.SetDPI(200);
                tiff_options.SetDither(true);
                tiff_options.SetMono(true);
                pdftron.PDF.Convert.ToTiff(inputPath + "newsletter.pdf", outputPath + "newsletter.tiff", tiff_options);
                Console.WriteLine("Saved newsletter.tiff");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

            return err;
        }

        static Boolean ConvertToPdfFromFile()
        {
            System.Collections.ArrayList testfiles = new System.Collections.ArrayList();
            testfiles.Add(new ConvertTestCS.Testfile("simple-word_2007.docx", "docx2pdf.pdf", false));
            testfiles.Add(new ConvertTestCS.Testfile("simple-powerpoint_2007.pptx", "pptx2pdf.pdf", false));
            testfiles.Add(new ConvertTestCS.Testfile("simple-excel_2007.xlsx", "xlsx2pdf.pdf", false));
            testfiles.Add(new ConvertTestCS.Testfile("simple-publisher.pub", "pub2pdf.pdf", true));
            testfiles.Add(new ConvertTestCS.Testfile("simple-text.txt", "txt2pdf.pdf", false));
            testfiles.Add(new ConvertTestCS.Testfile("simple-rtf.rtf", "rtf2pdf.pdf", true));
            testfiles.Add(new ConvertTestCS.Testfile("butterfly.png", "png2pdf.pdf", false));
            testfiles.Add(new ConvertTestCS.Testfile("simple-emf.emf", "emf2pdf.pdf", true));
            testfiles.Add(new ConvertTestCS.Testfile("simple-xps.xps", "xps2pdf.pdf", false));
            // testfiles.Add(new ConvertTestCS.Testfile("simple-webpage.mht", "mht2pdf.pdf", true));
            testfiles.Add(new ConvertTestCS.Testfile("simple-webpage.html", "html2pdf.pdf", true));

            bool err = false;
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                try
                {
                    if (pdftron.PDF.Convert.Printer.IsInstalled("PDFTron PDFNet"))
                    {
                        pdftron.PDF.Convert.Printer.SetPrinterName("PDFTron PDFNet");
                    }
                    else if (!pdftron.PDF.Convert.Printer.IsInstalled())
                    {
                        try
                        {
                            Console.WriteLine("Installing printer (requires Windows platform and administrator)");
                            pdftron.PDF.Convert.Printer.Install();
                            Console.WriteLine("Installed printer " + pdftron.PDF.Convert.Printer.GetPrinterName());
                            // the function ConvertToXpsFromFile may require the printer so leave it installed
                            // uninstallPrinterWhenDone = true;
                        }
                        catch (PDFNetException e)
                        {
                            Console.WriteLine("ERROR: Unable to install printer.");
                            Console.WriteLine(e.Message);
                            err = true;
                        }
                        catch
                        {
                            Console.WriteLine("ERROR: Unable to install printer. Make sure that the package's bitness matches your operating system's bitness and that you are running with administrator privileges.");
                        }
                    }
                }
                catch (PDFNetException e)
                {
                    Console.WriteLine("ERROR: Unable to install printer.");
                    Console.WriteLine(e.Message);
                    err = true;
                }
            }
            foreach (Testfile file in testfiles)
            {
                if ( Environment.OSVersion.Platform != PlatformID.Win32NT)
                {
                    if (file.requiresWindowsPlatform)
                    {
                        continue;
                    }
                }
                try
                {
                    using (pdftron.PDF.PDFDoc pdfdoc = new PDFDoc())
                    {

                        if (pdftron.PDF.Convert.RequiresPrinter(inputPath + file.inputFile))
                        {
                            Console.WriteLine("Using PDFNet printer to convert file " + file.inputFile);
                        }
                        pdftron.PDF.Convert.ToPdf(pdfdoc, inputPath + file.inputFile);
                        pdfdoc.Save(outputPath + file.outputFile, SDFDoc.SaveOptions.e_linearized);
                        Console.WriteLine("Converted file: " + file.inputFile);
                        Console.WriteLine("to: " + file.outputFile);
                    }
                }
                catch (PDFNetException e)
                {
                    Console.WriteLine("ERROR: on input file " + file.inputFile);
                    Console.WriteLine(e.Message);
                    err = true;
                }
            }

            return err;
        }
        [STAThread]
        static void Main(string [] args)
        {
            PDFNet.Initialize(PDFTronLicense.Key);
            bool err = false;

            err = ConvertToPdfFromFile();
            if (err)
            {
                Console.WriteLine("ConvertFile failed");
            }
            else
            {
                Console.WriteLine("ConvertFile succeeded");
            }

            err = ConvertSpecificFormats();
            if (err)
            {
                Console.WriteLine("ConvertSpecificFormats failed");
            }
            else
            {
                Console.WriteLine("ConvertSpecificFormats succeeded");
            }

            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                if (pdftron.PDF.Convert.Printer.IsInstalled())
                {
                    try
                    {
                        Console.WriteLine("Uninstalling printer (requires Windows platform and administrator)");
                        pdftron.PDF.Convert.Printer.Uninstall();
                        Console.WriteLine("Uninstalled Printer " + pdftron.PDF.Convert.Printer.GetPrinterName());
                    }
                    catch
                    {
                        Console.WriteLine("Unable to uninstall printer");
                    }
                }
            }
            PDFNet.Terminate();
            Console.WriteLine("Done.");
        }
    }
}
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;

// The following code showcases the conversion of documents to formats // such as SVG, PDF, EMF, or XPS.

namespace ConvertTestCS
{
    class Testfile
    {
        public string inputFile, outputFile;
        public bool requiresWindowsPlatform;
        public Testfile(string inFile, string outFile, bool requiresWindowsPlatform_)
        {
            inputFile = inFile;
            outputFile = outFile;
            requiresWindowsPlatform = requiresWindowsPlatform_;
        }
    };

    class Class1
    {
        private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
        static Class1() {}

        // Relative path to the folder containing test files.
        const string inputPath = "../../../../TestFiles/";
        const string outputPath = "../../../../TestFiles/Output/";

        static bool ConvertSpecificFormats()
        {
            bool err = false;
            try
            {
                using (PDFDoc pdfdoc = new PDFDoc())
                {
                    Console.WriteLine("Converting from XPS");
                    pdftron.PDF.Convert.FromXps(pdfdoc, inputPath + "simple-xps.xps");
                    pdfdoc.Save(outputPath + "xps2pdf v2.pdf", SDFDoc.SaveOptions.e_remove_unused);
                    Console.WriteLine("Saved xps2pdf v2.pdf");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

    /////////////////////////////////////////////
    if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
                try
                {
                    using (PDFDoc pdfdoc = new PDFDoc())
                    {
                        Console.WriteLine("Converting from EMF");
                        pdftron.PDF.Convert.FromEmf(pdfdoc, inputPath + "simple-emf.emf");
                        pdfdoc.Save(outputPath + "emf2pdf v2.pdf", SDFDoc.SaveOptions.e_remove_unused);
                        Console.WriteLine("Saved emf2pdf v2.pdf");
                    }
                }
                catch (PDFNetException e)
                {
                    Console.WriteLine(e.Message);
                    err = true;
                }
            }

        ///////////////////////////////////////////
            try
            {
                using (PDFDoc pdfdoc = new PDFDoc())
                {
                    // Add a dictionary
                    ObjSet set = new ObjSet();
                    Obj options = set.CreateDict();

                    // Put options
                    options.PutNumber("FontSize", 15);
                    options.PutBool("UseSourceCodeFormatting", true);
                    options.PutNumber("PageWidth", 12);
                    options.PutNumber("PageHeight", 6);

                    // Convert from .txt file
                    Console.WriteLine("Converting from txt");
                    pdftron.PDF.Convert.FromText(pdfdoc, inputPath + "simple-text.txt", options);
                    pdfdoc.Save(outputPath + "simple-text.pdf", SDFDoc.SaveOptions.e_remove_unused);
                    Console.WriteLine("Saved simple-text.pdf");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

    ///////////////////////////////////////////
            try
            {
                using (PDFDoc pdfdoc = new PDFDoc(inputPath + "newsletter.pdf"))
                {
                    // Convert PDF document to SVG
                    Console.WriteLine("Converting pdfdoc to SVG");
                    pdftron.PDF.Convert.ToSvg(pdfdoc, outputPath + "pdf2svg v2.svg");
                    Console.WriteLine("Saved pdf2svg v2.svg");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

    /////////////////////////////////////////////////
            try
            {
                // Convert PNG image to XPS
                Console.WriteLine("Converting PNG to XPS");
                pdftron.PDF.Convert.ToXps(inputPath + "butterfly.png", outputPath + "butterfly.xps");
                Console.WriteLine("Saved butterfly.xps");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }
    ///////////////////////////////////////////
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                try
                {
                    // Convert MSWord document to XPS
                    Console.WriteLine("Converting DOCX to XPS");
                    pdftron.PDF.Convert.ToXps(inputPath + "simple-word_2007.docx", outputPath + "simple-word_2007.xps");
                    Console.WriteLine("Saved simple-word_2007.xps");
                }
                catch (PDFNetException e)
                {
                    Console.WriteLine(e.Message);
                    err = true;
                }
            }
            ////////////////////////////////////////////////////////////////////
            try
            {
                // Convert PDF document to XPS
                Console.WriteLine("Converting PDF to XPS");
                pdftron.PDF.Convert.ToXps(inputPath + "newsletter.pdf", outputPath + "newsletter.xps");
                Console.WriteLine("Saved newsletter.xps");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

            //////////////////////////////////////////////////////////////////////
            try
            {
                // Convert PDF document to HTML
                Console.WriteLine("Converting PDF to HTML");
                pdftron.PDF.Convert.ToHtml(inputPath + "newsletter.pdf", outputPath + "newsletter");
                Console.WriteLine("Saved newsletter as HTML");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

            //////////////////////////////////////////////////////////////////////
            try
            {
                // Convert PDF document to EPUB
                Console.WriteLine("Converting PDF to EPUB");
                pdftron.PDF.Convert.ToEpub(inputPath + "newsletter.pdf", outputPath + "newsletter.epub");
                Console.WriteLine("Saved newsletter.epub");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

            /////////////////////////////////////////////////////////////////////
            try
            {
                // Convert PDF document to multipage TIFF
                Console.WriteLine("Converting PDF to multipage TIFF");
                pdftron.PDF.Convert.TiffOutputOptions tiff_options = new pdftron.PDF.Convert.TiffOutputOptions();
                tiff_options.SetDPI(200);
                tiff_options.SetDither(true);
                tiff_options.SetMono(true);
                pdftron.PDF.Convert.ToTiff(inputPath + "newsletter.pdf", outputPath + "newsletter.tiff", tiff_options);
                Console.WriteLine("Saved newsletter.tiff");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
                err = true;
            }

            return err;
        }

        static Boolean ConvertToPdfFromFile()
        {
            System.Collections.ArrayList testfiles = new System.Collections.ArrayList();
            testfiles.Add(new ConvertTestCS.Testfile("simple-word_2007.docx", "docx2pdf.pdf", false));
            testfiles.Add(new ConvertTestCS.Testfile("simple-powerpoint_2007.pptx", "pptx2pdf.pdf", false));
            testfiles.Add(new ConvertTestCS.Testfile("simple-excel_2007.xlsx", "xlsx2pdf.pdf", false));
            testfiles.Add(new ConvertTestCS.Testfile("simple-publisher.pub", "pub2pdf.pdf", true));
            testfiles.Add(new ConvertTestCS.Testfile("simple-text.txt", "txt2pdf.pdf", false));
            testfiles.Add(new ConvertTestCS.Testfile("simple-rtf.rtf", "rtf2pdf.pdf", true));
            testfiles.Add(new ConvertTestCS.Testfile("butterfly.png", "png2pdf.pdf", false));
            testfiles.Add(new ConvertTestCS.Testfile("simple-emf.emf", "emf2pdf.pdf", true));
            testfiles.Add(new ConvertTestCS.Testfile("simple-xps.xps", "xps2pdf.pdf", false));
            // testfiles.Add(new ConvertTestCS.Testfile("simple-webpage.mht", "mht2pdf.pdf", true));
            testfiles.Add(new ConvertTestCS.Testfile("simple-webpage.html", "html2pdf.pdf", true));

            bool err = false;
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                try
                {
                    if (pdftron.PDF.Convert.Printer.IsInstalled("PDFTron PDFNet"))
                    {
                        pdftron.PDF.Convert.Printer.SetPrinterName("PDFTron PDFNet");
                    }
                    else if (!pdftron.PDF.Convert.Printer.IsInstalled())
                    {
                        try
                        {
                            Console.WriteLine("Installing printer (requires Windows platform and administrator)");
                            pdftron.PDF.Convert.Printer.Install();
                            Console.WriteLine("Installed printer " + pdftron.PDF.Convert.Printer.GetPrinterName());
                            // the function ConvertToXpsFromFile may require the printer so leave it installed
                            // uninstallPrinterWhenDone = true;
                        }
                        catch (PDFNetException e)
                        {
                            Console.WriteLine("ERROR: Unable to install printer.");
                            Console.WriteLine(e.Message);
                            err = true;
                        }
                        catch
                        {
                            Console.WriteLine("ERROR: Unable to install printer. Make sure that the package's bitness matches your operating system's bitness and that you are running with administrator privileges.");
                        }
                    }
                }
                catch (PDFNetException e)
                {
                    Console.WriteLine("ERROR: Unable to install printer.");
                    Console.WriteLine(e.Message);
                    err = true;
                }
            }
            foreach (Testfile file in testfiles)
            {
                if ( Environment.OSVersion.Platform != PlatformID.Win32NT)
                {
                    if (file.requiresWindowsPlatform)
                    {
                        continue;
                    }
                }
                try
                {
                    using (pdftron.PDF.PDFDoc pdfdoc = new PDFDoc())
                    {

                        if (pdftron.PDF.Convert.RequiresPrinter(inputPath + file.inputFile))
                        {
                            Console.WriteLine("Using PDFNet printer to convert file " + file.inputFile);
                        }
                        pdftron.PDF.Convert.ToPdf(pdfdoc, inputPath + file.inputFile);
                        pdfdoc.Save(outputPath + file.outputFile, SDFDoc.SaveOptions.e_linearized);
                        Console.WriteLine("Converted file: " + file.inputFile);
                        Console.WriteLine("to: " + file.outputFile);
                    }
                }
                catch (PDFNetException e)
                {
                    Console.WriteLine("ERROR: on input file " + file.inputFile);
                    Console.WriteLine(e.Message);
                    err = true;
                }
            }

            return err;
        }
        [STAThread]
        static void Main(string [] args)
        {
            PDFNet.Initialize(PDFTronLicense.Key);
            bool err = false;

            err = ConvertToPdfFromFile();
            if (err)
            {
                Console.WriteLine("ConvertFile failed");
            }
            else
            {
                Console.WriteLine("ConvertFile succeeded");
            }

            err = ConvertSpecificFormats();
            if (err)
            {
                Console.WriteLine("ConvertSpecificFormats failed");
            }
            else
            {
                Console.WriteLine("ConvertSpecificFormats succeeded");
            }

            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                if (pdftron.PDF.Convert.Printer.IsInstalled())
                {
                    try
                    {
                        Console.WriteLine("Uninstalling printer (requires Windows platform and administrator)");
                        pdftron.PDF.Convert.Printer.Uninstall();
                        Console.WriteLine("Uninstalled Printer " + pdftron.PDF.Convert.Printer.GetPrinterName());
                    }
                    catch
                    {
                        Console.WriteLine("Unable to uninstall printer");
                    }
                }
            }
            PDFNet.Terminate();
            Console.WriteLine("Done.");
        }
    }
}
' Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.

Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports pdftron
Imports pdftron.Common
Imports pdftron.Filters
Imports pdftron.SDF
Imports pdftron.PDF

' The following code showcases the conversion of documents to formats // such as SVG, PDF, EMF, or XPS.

Namespace ConvertTestCS
	Friend Class Testfile
		Public inputFile, outputFile As String
		Public requiresWindowsPlatform As Boolean
		Public Sub New(ByVal inFile As String, ByVal outFile As String, ByVal requiresWindowsPlatform_ As Boolean)
			inputFile = inFile
			outputFile = outFile
			requiresWindowsPlatform = requiresWindowsPlatform_
		End Sub
	End Class

	Friend Class Class1
		Private Shared pdfNetLoader As pdftron.PDFNetLoader = pdftron.PDFNetLoader.Instance()
		Shared Sub New()
		End Sub

		' Relative path to the folder containing test files.
		Private Const inputPath As String = "../../../../TestFiles/"
		Private Const outputPath As String = "../../../../TestFiles/Output/"

		Private Shared Function ConvertSpecificFormats() As Boolean
			Dim err As Boolean = False
			Try
				Using pdfdoc As New PDFDoc()
					Console.WriteLine("Converting from XPS")
					pdftron.PDF.Convert.FromXps(pdfdoc, inputPath & "simple-xps.xps")
					pdfdoc.Save(outputPath & "xps2pdf v2.pdf", SDFDoc.SaveOptions.e_remove_unused)
					Console.WriteLine("Saved xps2pdf v2.pdf")
				End Using
			Catch e As PDFNetException
				Console.WriteLine(e.Message)
				err = True
			End Try

	'///////////////////////////////////////////
	If Environment.OSVersion.Platform = PlatformID.Win32NT Then
				Try
					Using pdfdoc As New PDFDoc()
						Console.WriteLine("Converting from EMF")
						pdftron.PDF.Convert.FromEmf(pdfdoc, inputPath & "simple-emf.emf")
						pdfdoc.Save(outputPath & "emf2pdf v2.pdf", SDFDoc.SaveOptions.e_remove_unused)
						Console.WriteLine("Saved emf2pdf v2.pdf")
					End Using
				Catch e As PDFNetException
					Console.WriteLine(e.Message)
					err = True
				End Try
	End If

		'/////////////////////////////////////////
			Try
				Using pdfdoc As New PDFDoc()
					' Add a dictionary
					Dim [set] As New ObjSet()
					Dim options As Obj = [set].CreateDict()

					' Put options
					options.PutNumber("FontSize", 15)
					options.PutBool("UseSourceCodeFormatting", True)
					options.PutNumber("PageWidth", 12)
					options.PutNumber("PageHeight", 6)

					' Convert from .txt file
					Console.WriteLine("Converting from txt")
					pdftron.PDF.Convert.FromText(pdfdoc, inputPath & "simple-text.txt", options)
					pdfdoc.Save(outputPath & "simple-text.pdf", SDFDoc.SaveOptions.e_remove_unused)
					Console.WriteLine("Saved simple-text.pdf")
				End Using
			Catch e As PDFNetException
				Console.WriteLine(e.Message)
				err = True
			End Try

	'/////////////////////////////////////////
			Try
				Using pdfdoc As New PDFDoc(inputPath & "newsletter.pdf")
					' Convert PDF document to SVG
					Console.WriteLine("Converting pdfdoc to SVG")
					pdftron.PDF.Convert.ToSvg(pdfdoc, outputPath & "pdf2svg v2.svg")
					Console.WriteLine("Saved pdf2svg v2.svg")
				End Using
			Catch e As PDFNetException
				Console.WriteLine(e.Message)
				err = True
			End Try

	'///////////////////////////////////////////////
			Try
				' Convert PNG image to XPS
				Console.WriteLine("Converting PNG to XPS")
				pdftron.PDF.Convert.ToXps(inputPath & "butterfly.png", outputPath & "butterfly.xps")
				Console.WriteLine("Saved butterfly.xps")
			Catch e As PDFNetException
				Console.WriteLine(e.Message)
				err = True
			End Try
	'/////////////////////////////////////////
			If Environment.OSVersion.Platform = PlatformID.Win32NT Then
				Try
					' Convert MSWord document to XPS
					Console.WriteLine("Converting DOCX to XPS")
					pdftron.PDF.Convert.ToXps(inputPath & "simple-word_2007.docx", outputPath & "simple-word_2007.xps")
					Console.WriteLine("Saved simple-word_2007.xps")
				Catch e As PDFNetException
					Console.WriteLine(e.Message)
					err = True
				End Try
			End If
			'//////////////////////////////////////////////////////////////////
			Try
				' Convert PDF document to XPS
				Console.WriteLine("Converting PDF to XPS")
				pdftron.PDF.Convert.ToXps(inputPath & "newsletter.pdf", outputPath & "newsletter.xps")
				Console.WriteLine("Saved newsletter.xps")
			Catch e As PDFNetException
				Console.WriteLine(e.Message)
				err = True
			End Try

			'////////////////////////////////////////////////////////////////////
			Try
				' Convert PDF document to HTML
				Console.WriteLine("Converting PDF to HTML")
				pdftron.PDF.Convert.ToHtml(inputPath & "newsletter.pdf", outputPath & "newsletter")
				Console.WriteLine("Saved newsletter as HTML")
			Catch e As PDFNetException
				Console.WriteLine(e.Message)
				err = True
			End Try

			'////////////////////////////////////////////////////////////////////
			Try
				' Convert PDF document to EPUB
				Console.WriteLine("Converting PDF to EPUB")
				pdftron.PDF.Convert.ToEpub(inputPath & "newsletter.pdf", outputPath & "newsletter.epub")
				Console.WriteLine("Saved newsletter.epub")
			Catch e As PDFNetException
				Console.WriteLine(e.Message)
				err = True
			End Try

			'///////////////////////////////////////////////////////////////////
			Try
				' Convert PDF document to multipage TIFF
				Console.WriteLine("Converting PDF to multipage TIFF")
				Dim tiff_options As New pdftron.PDF.Convert.TiffOutputOptions()
				tiff_options.SetDPI(200)
				tiff_options.SetDither(True)
				tiff_options.SetMono(True)
				pdftron.PDF.Convert.ToTiff(inputPath & "newsletter.pdf", outputPath & "newsletter.tiff", tiff_options)
				Console.WriteLine("Saved newsletter.tiff")
			Catch e As PDFNetException
				Console.WriteLine(e.Message)
				err = True
			End Try

			Return err
		End Function

		Private Shared Function ConvertToPdfFromFile() As Boolean
			Dim testfiles As New System.Collections.ArrayList()
			testfiles.Add(New ConvertTestCS.Testfile("simple-word_2007.docx", "docx2pdf.pdf", False))
			testfiles.Add(New ConvertTestCS.Testfile("simple-powerpoint_2007.pptx", "pptx2pdf.pdf", False))
			testfiles.Add(New ConvertTestCS.Testfile("simple-excel_2007.xlsx", "xlsx2pdf.pdf", False))
			testfiles.Add(New ConvertTestCS.Testfile("simple-publisher.pub", "pub2pdf.pdf", True))
			testfiles.Add(New ConvertTestCS.Testfile("simple-text.txt", "txt2pdf.pdf", False))
			testfiles.Add(New ConvertTestCS.Testfile("simple-rtf.rtf", "rtf2pdf.pdf", True))
			testfiles.Add(New ConvertTestCS.Testfile("butterfly.png", "png2pdf.pdf", False))
			testfiles.Add(New ConvertTestCS.Testfile("simple-emf.emf", "emf2pdf.pdf", True))
			testfiles.Add(New ConvertTestCS.Testfile("simple-xps.xps", "xps2pdf.pdf", False))
			' testfiles.Add(new ConvertTestCS.Testfile("simple-webpage.mht", "mht2pdf.pdf", true));
			testfiles.Add(New ConvertTestCS.Testfile("simple-webpage.html", "html2pdf.pdf", True))

			Dim err As Boolean = False
			If Environment.OSVersion.Platform = PlatformID.Win32NT Then
				Try
					If pdftron.PDF.Convert.Printer.IsInstalled("PDFTron PDFNet") Then
						pdftron.PDF.Convert.Printer.SetPrinterName("PDFTron PDFNet")
					ElseIf Not pdftron.PDF.Convert.Printer.IsInstalled() Then
						Try
							Console.WriteLine("Installing printer (requires Windows platform and administrator)")
							pdftron.PDF.Convert.Printer.Install()
							Console.WriteLine("Installed printer " & pdftron.PDF.Convert.Printer.GetPrinterName())
							' the function ConvertToXpsFromFile may require the printer so leave it installed
							' uninstallPrinterWhenDone = true;
						Catch e As PDFNetException
							Console.WriteLine("ERROR: Unable to install printer.")
							Console.WriteLine(e.Message)
							err = True
						Catch
							Console.WriteLine("ERROR: Unable to install printer. Make sure that the package's bitness matches your operating system's bitness and that you are running with administrator privileges.")
						End Try
					End If
				Catch e As PDFNetException
					Console.WriteLine("ERROR: Unable to install printer.")
					Console.WriteLine(e.Message)
					err = True
				End Try
			End If
			For Each file As Testfile In testfiles
				If Environment.OSVersion.Platform <> PlatformID.Win32NT Then
					If file.requiresWindowsPlatform Then
						Continue For
					End If
				End If
				Try
					Using pdfdoc As pdftron.PDF.PDFDoc = New PDFDoc()

						If pdftron.PDF.Convert.RequiresPrinter(inputPath & file.inputFile) Then
							Console.WriteLine("Using PDFNet printer to convert file " & file.inputFile)
						End If
						pdftron.PDF.Convert.ToPdf(pdfdoc, inputPath & file.inputFile)
						pdfdoc.Save(outputPath & file.outputFile, SDFDoc.SaveOptions.e_linearized)
						Console.WriteLine("Converted file: " & file.inputFile)
						Console.WriteLine("to: " & file.outputFile)
					End Using
				Catch e As PDFNetException
					Console.WriteLine("ERROR: on input file " & file.inputFile)
					Console.WriteLine(e.Message)
					err = True
				End Try
			Next file

			Return err
		End Function
		<STAThread>
		Shared Sub Main(ByVal args() As String)
			PDFNet.Initialize(PDFTronLicense.Key)
			Dim err As Boolean = False

			err = ConvertToPdfFromFile()
			If err Then
				Console.WriteLine("ConvertFile failed")
			Else
				Console.WriteLine("ConvertFile succeeded")
			End If

			err = ConvertSpecificFormats()
			If err Then
				Console.WriteLine("ConvertSpecificFormats failed")
			Else
				Console.WriteLine("ConvertSpecificFormats succeeded")
			End If

			If Environment.OSVersion.Platform = PlatformID.Win32NT Then
				If pdftron.PDF.Convert.Printer.IsInstalled() Then
					Try
						Console.WriteLine("Uninstalling printer (requires Windows platform and administrator)")
						pdftron.PDF.Convert.Printer.Uninstall()
						Console.WriteLine("Uninstalled Printer " & pdftron.PDF.Convert.Printer.GetPrinterName())
					Catch
						Console.WriteLine("Unable to uninstall printer")
					End Try
				End If
			End If
			PDFNet.Terminate()
			Console.WriteLine("Done.")
		End Sub
	End Class
End Namespace
VB   C#

5.2 使用 IronOCR

使用 OCRInput 函数可完成对 PDF 文件的管理。文件中的每一页都将被 Iron Tesseract 类读取。然后从页面中提取文本。第二个名为 "AddPDF "的函数允许我们打开受保护的文档,并确保我们能将 PDF 文件添加到文档列表中。 (如果密码受到保护).要打开受密码保护的 PDF 文档,请使用下面的代码片段:

var Ocr = new IronTesseract(); // nothing to configure
using (var Input = new OcrInput())
{
    Input.AddPdf("example.pdf", "password");
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}
var Ocr = new IronTesseract(); // nothing to configure
using (var Input = new OcrInput())
{
    Input.AddPdf("example.pdf", "password");
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}
Dim Ocr = New IronTesseract() ' nothing to configure
Using Input = New OcrInput()
	Input.AddPdf("example.pdf", "password")
	Dim Result = Ocr.Read(Input)
	Console.WriteLine(Result.Text)
End Using
VB   C#

利用 "Addpdfpage "功能可以读取和提取 PDF 文件中某一页的内容。只需指定要从中提取文本的准确页码。"AddPdfPage "允许您从指定的多个页面中提取文本。IEnumerable可以让您有效地指定多个页面。您还必须包含文件的位置和扩展名。下面的代码片段演示了这一点:

IEnumerable<int> numbers = new List<int> {2,8,10 };
 var Ocr = new IronTesseract();
using (var Input = new OcrInput())
{
    //single page
    Input.AddPdfPage("example.pdf",10);
    //Multiple page
    Input.AddPdfPages("example.pdf", numbers);
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
    Result.SaveAsTextFile("ocrtext.txt");
}
IEnumerable<int> numbers = new List<int> {2,8,10 };
 var Ocr = new IronTesseract();
using (var Input = new OcrInput())
{
    //single page
    Input.AddPdfPage("example.pdf",10);
    //Multiple page
    Input.AddPdfPages("example.pdf", numbers);
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
    Result.SaveAsTextFile("ocrtext.txt");
}
Dim numbers As IEnumerable(Of Integer) = New List(Of Integer) From {2, 8, 10}
 Dim Ocr = New IronTesseract()
Using Input = New OcrInput()
	'single page
	Input.AddPdfPage("example.pdf",10)
	'Multiple page
	Input.AddPdfPages("example.pdf", numbers)
	Dim Result = Ocr.Read(Input)
	Console.WriteLine(Result.Text)
	Result.SaveAsTextFile("ocrtext.txt")
End Using
VB   C#

使用 SaveAsTextFile 函数可直接将结果存储为文本文件格式,这样就可以直接将文件下载到输出目录路径。要将文件保存为 HTML 格式,请使用 SaveAsHocrFile。

6.1 使用 PDFTron

我们可以使用 PDFTron SDK 从 PDF 文件中提取图像及其定位信息和 DPI。您也可以使用 elements.GetImageData 直接提取未压缩/已压缩的图像数据,而不是将 PDF 图像转换为位图。() (中描述的 PDF 数据提取代码示例).进一步了解我们的 C# PDF 库以及 PDF 解析和内容提取库。

6.2 使用 IronOCR

IronOCR 拥有大量令人印象深刻的功能,可让您直接从扫描的文档中读取 QR 码和条形码。下面的代码片段演示了如何从给定的图像或文档中扫描条形码。

var Ocr = new IronTesseract(); // nothing to configure
Ocr.Language = OcrLanguage.EnglishBest;
Ocr.Configuration.ReadBarCodes = true;
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
using (var Input = new OcrInput())
{
    Input.AddImage("barcode.gif");
    var Result = Ocr.Read(Input);

    foreach (var Barcode in Result.Barcodes)
    {
        Console.WriteLine(Barcode.Value);
    }
}
var Ocr = new IronTesseract(); // nothing to configure
Ocr.Language = OcrLanguage.EnglishBest;
Ocr.Configuration.ReadBarCodes = true;
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
using (var Input = new OcrInput())
{
    Input.AddImage("barcode.gif");
    var Result = Ocr.Read(Input);

    foreach (var Barcode in Result.Barcodes)
    {
        Console.WriteLine(Barcode.Value);
    }
}
Dim Ocr = New IronTesseract() ' nothing to configure
Ocr.Language = OcrLanguage.EnglishBest
Ocr.Configuration.ReadBarCodes = True
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5
Using Input = New OcrInput()
	Input.AddImage("barcode.gif")
	Dim Result = Ocr.Read(Input)

	For Each Barcode In Result.Barcodes
		Console.WriteLine(Barcode.Value)
	Next Barcode
End Using
VB   C#

以上代码有助于从给定图像或 PDF 文档中读取条形码。在单个图像或页面中,可以同时读取多个条形码。IronOCR 有一个读取条形码的独特方法,即 Ocr.Configuration.ReadBarCodes。

扫描输入后,数据将存储在一个名为 OCRResult 的对象中。OCRResult 中的属性名为 "条形码",其中包含所有可用条形码数据的列表。我们可以通过 for-each 循环获取与条形码详细信息相关的每个数据。扫描和读取条形码值这两个操作在一个流程中完成。

此外,IronOCR 还支持线程选项,可同时完成多个 OCR 进程。此外,IronOCR 还能识别指定区域中的精确区域。

var Ocr = new IronTesseract();
using (var Input = new OcrInput())
{
    var ContentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
    Input.Add("document.png", ContentArea);
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}
var Ocr = new IronTesseract();
using (var Input = new OcrInput())
{
    var ContentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
    Input.Add("document.png", ContentArea);
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}
Dim Ocr = New IronTesseract()
Using Input = New OcrInput()
	Dim ContentArea = New System.Drawing.Rectangle() With {
		.X = 215,
		.Y = 1250,
		.Height = 280,
		.Width = 1335
	}
	Input.Add("document.png", ContentArea)
	Dim Result = Ocr.Read(Input)
	Console.WriteLine(Result.Text)
End Using
VB   C#

上面的代码片段演示了如何对特定区域执行 OCR。您只需在 PDF/图像中指定矩形区域,IronOCRs Tesseract 引擎就会帮助识别文本。

IronOCR 和 PDFtron OCR 许可证模式和定价

IronOCR 许可证模式和定价

30 天退款保证: 一旦购买许可证,您将获得 30 天退款保证。在这 30 天内,如果您想退货,您将收到退款。

轻松集成: IronOCR 与任何项目和环境的集成都非常简单,只需在一行代码中将其添加为 NuGet 软件包。另一方面,集成环境的另一种方法是从网上直接下载。

永久许可证: 购买的每个许可证都无需更新。

免费支持和产品更新:每个许可证都将直接获得产品背后团队的支持,并附带一年的免费产品更新。可随时购买扩展功能。

立即许可证: 收到付款后,将立即发送注册许可证密钥。

所有许可证均为永久许可证,适用于开发、暂存和生产。

简装版许可证

  • 1 开发人员
  • 1 个地点
  • 1 个项目
  • 永久许可证

该软件包允许企业中的单个软件开发人员在一个位置使用 Iron 软件。Iron 软件可用于单个内部网应用程序、网络应用程序或桌面软件程序。禁止在组织或代理/客户关系之外共享许可证,因为它们是不可转让的。本许可类型与所有其他许可类型一样,明确排除本协议未明确授予的所有权利,不进行 OEM 再分发,也不在不购买额外保险的情况下将 Iron 软件作为 SaaS 使用。

定价: 每年 $749 起。

专业执照

  • 10 名开发人员
  • 10 个地点
  • 10 个项目
  • 永久许可证

该许可证允许企业中预先确定数量的软件开发人员在多个地点使用 Iron 软件,最多不超过 10 人。您可以在任意数量的网站、内联网应用程序或桌面软件应用程序中使用 Iron 软件。许可证不可转让,也不能在组织或代理/客户关系之外共享。与所有其他许可类型一样,本许可类型明确排除本协议未明确授予的所有权利,包括 OEM 再分发和在不购买额外保险的情况下将 Iron 软件作为 SaaS 使用。本许可最多可与 10 个项目集成。

定价: 每年 999 美元起。

无限许可

  • 无限开发者
  • 不限地点
  • 无限项目
  • 永久许可证

该许可证允许企业中数量不限的软件开发人员在数量不限的地点使用 Iron 软件。您可以在任意数量的内网应用程序、桌面软件应用程序或网站中使用 Iron 软件。许可证不可转让,也不能在组织或代理/客户关系之外共享。本许可类型与所有其他许可类型一样,明确排除本协议未授予的所有权利,包括 OEM 再分发和在未购买额外保险的情况下将 Iron 软件作为 SaaS 使用。

定价: 每年 $2,999 起。

免版税再分发 — 允许您将 Iron 软件作为多种不同包装的商业产品的一部分进行分发。 (无需支付版税) 基于基本许可证所涵盖的项目数量。这将允许在 SaaS 软件服务中部署 Iron 软件,而 SaaS 软件服务是基于基本许可证所涵盖的项目数量。

定价: 每年 1599 美元起。

PDFTron 许可证模式和定价

PDFTron 软件包 (自定义许可证)

  • 定制许可证的价格各不相同,请根据您的具体预算进行报价。
  • 部署 PDFTron 强大的文档查看和编辑技术,在网络、移动和桌面平台上进行渲染和文档处理
  • 适用于集成、OEM 再分发以及具有大量文档或特殊要求的组织
  • 多域定价和优惠的多年折扣
  • 支持离线和沙盒操作
  • 定制、全面的合同条款

  • 咨询和培训服务

PDFTron 定制许可证可根据您的应用和业务需求量身定制。定价取决于您的功能范围。

IronOCR Lite许可证是一个未定义的软件包,包括一个开发人员和一年的支持,价格约为liteLicense美元。IronOCR 专业许可证包括10个开发包和一年的支持,价格为999美元。要购买软件包,您必须联系支持中心获取报价。

IronOCR LiteProfessional套餐包括OEM或SaaS服务,支持期为5年。Lite 版本包括一个开发人员软件包,提供 5 年支持,Saas 和 OEM 服务费用为 2,897 美元,有定制支持选项。IronOCR 专业版包括10个开发包,提供5年支持、Saas和OEM服务,价格为3397美元。PDFTron 的 10 个开发人员套餐包括一年支持、Saas 和 OEM 服务,没有明确的价格。

7.0 结论

.NET框架中的IronOCR提供的Tesseract可以直接使用,并以多种方式支持照片和PDF文档。它还提供了多种设置来提高 Tesseract OCR 库的性能。它支持多种语言,一次操作可使用多种语言。访问其网站了解有关 Tesseract OCR 的更多信息。

PDFTron 是一款使用不同引擎识别图像和 PDF 文档的软件应用程序。它还提供各种设置来提高 OCR 处理的性能,并可选择多种语言。PDFTron 对页面转换的使用有限制。它还针对不同的操作系统提供不同的价格。

IronOCR 是一款极具竞争力的软件产品,其准确性高于竞争品牌。同类产品有时无法识别低质量的图像,导致字符未知。而 IronOCR 不仅能提供准确的结果,还能识别条形码数据,并从图像中读取条形码的价值。

IronOCR 软件包以单一价格为所有平台提供有竞争力的许可和支持。相比之下,PDFtrons 的 OCR 产品都是专门定制的,价格往往更高。这两种产品的定价各不相同,IronOCR 的起价为 $749,而 PDFTron 由于是定制选择,起价未定。总之,IronOCR 以较低的价格提供了更多的功能。

还等什么呢?免费试用对所有人开放。获取 许可证 在此立即开始!

< 前一页
Tesseract替代方案(2022更新)
下一步 >
IronOCR与Tesseract.NET的比较

准备开始了吗? 版本: 2024.9 刚刚发布

免费NuGet下载 总下载量: 2,319,721 查看许可证 >