快速入手光学字符识别控件Aspose.OCR!如何从PDF中提取文本

Aspose.OCR是一款字符识别组件,它使得开发人员可以添加OCR功能到他们的ASP.NET Web应用程序、web服务和windows应用程序中。它提供了一个简单的类集用于控制字符识别。Aspose.OCR目的是为那些需要在他们自己的应用程序中使用图像(BMP和TIFF)的开发人员提供需求。它允许开发人员快速而简单的从图像中提取文本,并节省了从头开发一个OCR解决方案的时间和精力。

Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格

Aspose.OCR 最新下载(qun:761297826)icon-default.png?t=N3I4https://www.evget.com/product/2884/download

PDF 文件是最常见的业务文档之一。在某些情况下,我们可能需要以编程方式阅读扫描的PDF文档。从扫描的PDF文件中提取文本的困难导致了工具的开发,这些工具可以更轻松地从此类PDF文档中阅读和检索文本。根据文档的内容,出于多种原因,从 PDF 文件中提取文本可能很有用。在本文中,我们将学习如何在C#中对PDF文档进行OCR并从PDF中提取文本。

OCR PDF 到文本 C# API

我们将使用 Aspose.OCR for .NET API 对 PDF 文档执行 OCR。它可以识别扫描的图像,智能手机照片,屏幕截图和图像区域。API 以最流行的文档和数据交换格式返回识别的文本结果。除了将图像转换为文本外,API 还可以根据扫描创建可搜索的 PDF。此外,它能够自动更正已识别文本中的拼写错误。

该 API 提供了 AsposeOcr 类,该类提供了执行 OCR 操作的各种方法。它提供了RecognizePdf(字符串,DocumentRecognitionSettings)方法来识别所提供的PDF文档中的文本。API 的 DocumentRecognitionSettings 类提供 PDF 识别过程的设置。类表示图像识别的结果。

OCR PDF 和从 C 语言的 PDF 中提取文本

我们可以对PDF文档执行OCR,并按照以下步骤提取识别的文本:

  1. 首先,创建 AsposeOcr 类的实例。
  2. 接下来,初始化 DocumentRecognitionSettings 类的对象。
  3. 然后,指定要用于 OCR 的语言。
  4. 之后,通过调用 RecognizePdf() 方法获取 RecognitionResult。它采用图像路径和文档识别设置对象作为参数。
  5. 最后,循环浏览识别结果列表并显示标识的文本。

以下示例代码演示如何在 C# 中对 PDF 文档进行 OCR 和提取识别的文本。

// This code example demonstrates how to OCR PDF documents and extract the recognized text.
// Initialize the PCR engine
AsposeOcr recognitionEngine = new AsposeOcr();

// Initialize recognition settings
DocumentRecognitionSettings recognitionSettings = new DocumentRecognitionSettings();

// Specify language for OCR. Multi-language by default
recognitionSettings.Language = Language.Eng;

// Recognize text from PDF
List<RecognitionResult> results = recognitionEngine.RecognizePdf("C:\\Files\\sample.pdf", recognitionSettings);

// Show the recognized text
foreach (RecognitionResult result in results)
{
Console.WriteLine(result.RecognitionText);
}

对 PDF 执行 OCR 并将文本保存在 C 语言中

我们可以对PDF文档执行OCR,并按照以下步骤保存识别的文本:

  1. 首先,创建 AsposeOcr 类的实例。
  2. 接下来,初始化 DocumentRecognitionSettings 类的对象。
  3. 然后,指定要用于 OCR 的语言。
  4. 之后,调用 RecognizePdf() 方法来获取 RecognitionResult。它采用图像路径和文档识别设置对象作为参数。
  5. 最后,使用 SaveMultipageDocument() 方法保存文本。它采用输出文件路径、SaveFormat 和 RecognitionResult 对象作为参数。

以下示例代码演示如何对 PDF 文档进行 OCR 并将识别的文本保存在 C# 中。

// This code example demonstrates how to OCR PDF documents and extract the recognized text.
// Initialize the PCR engine
AsposeOcr recognitionEngine = new AsposeOcr();

// Initialize recognition settings
DocumentRecognitionSettings recognitionSettings = new DocumentRecognitionSettings();

// Specify language for OCR. Multi-language by default
recognitionSettings.Language = Language.Eng;

// Recognize text from PDF
List<RecognitionResult> results = recognitionEngine.RecognizePdf("C:\\Files\\sample.pdf", recognitionSettings);

// Save the recognized text
AsposeOcr.SaveMultipageDocument("C:\\Files\\OCR_result.txt", SaveFormat.Text, results);

OCR PDF 和将扫描的 PDF 转换为 C 语言中的单词

我们可以对扫描的PDF文档执行OCR,并按照前面提到的步骤将识别的文本保存在Word文档中。但是,我们只需要在最后一步中指定 SaveFormat.Docx。

下面的示例代码演示如何在 C# 中对 PDF 进行 OCR PDF 并将识别的文本另存为 Word 文档。

// This code example demonstrates how to OCR PDF documents and save the recognized text as DOCX.
// Initialize the PCR engine
AsposeOcr recognitionEngine = new AsposeOcr();

// Initialize recognition settings
DocumentRecognitionSettings recognitionSettings = new DocumentRecognitionSettings();

// Specify language for OCR. Multi-language by default
recognitionSettings.Language = Language.Eng;

// Recognize text from PDF
List<RecognitionResult> results = recognitionEngine.RecognizePdf("C:\\Files\\sample.pdf", recognitionSettings);

// Save the recognized text as DOCX
AsposeOcr.SaveMultipageDocument("C:\\Files\\OCR_result.docx", SaveFormat.Docx, results);

OCR PDF 和 将 PDF 转换为 JSON 语言

我们可以对 PDF 文档执行 OCR,并按照前面提到的步骤将识别的文本保存在 JSON 文件中。但是,我们只需要在最后一步中指定 SaveFormat.Json。

以下示例代码演示如何在 C# 中对 PDF 进行 OCR PDF 并将识别的文本另存为 JSON 文件。

// This code example demonstrates how to OCR PDF documents and save the recognized text as JSON.
// Initialize the PCR engine
AsposeOcr recognitionEngine = new AsposeOcr();

// Initialize recognition settings
DocumentRecognitionSettings recognitionSettings = new DocumentRecognitionSettings();

// Specify language for OCR. Multi-language by default
recognitionSettings.Language = Language.Eng;

// Recognize text from PDF
List<RecognitionResult> results = recognitionEngine.RecognizePdf("C:\\Files\\sample.pdf", recognitionSettings);

// Save the recognized text as JSON
AsposeOcr.SaveMultipageDocument("C:\\Files\\OCR_result.json", SaveFormat.Json, results);

以上便是如何对 PDF 文档执行 OCR 以及如何在 C# 中从 PDF 中提取文本的详细步骤,希望能帮到您。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
坛子里有破解版的Asprise-OCR-Java,其原理就是利用开启CloseWin.exe窗口扫描有没有Asprise弹出过期的窗口,更具信息框的标题栏来判断是否要关闭此信息窗口。2011年7月以后的使用版无论是点击确定还是关闭按钮,都要跳转到Asprise网站。 此次真正破解的是AspriseOCR.dll这个文件。根据跟踪运行主要汇编代码如下: 10006CF4 . 50 push eax ; /pSystemTime 10006CF5 . FF15 C0931110 call dword ptr ds:[; \GetSystemTime 10006D19 . 68 02000080 push 0x80000002 ; |hKey = HKEY_LOCAL_MACHINE 10006D1E . FF15 10901110 call dword ptr ds:[; \RegCreateKeyExA 110006D39 . 68 9CA61110 push AspriseO.1011A69C ; |Title = "All rights reserved. Lab Asprise! (c) 1998-2008" 10006D3E . 68 D0A71110 push AspriseO.1011A7D0 ; |Text = "You are using the trial version of Asprise OCR. Do you want to remove this message box by buying a very affordable license from Lab Asprise? " 10006D53 . 68 98A71110 push AspriseO.1011A798 ; |FileName = "http://asprise.com/product/ocr/index.php?Ref=Eval" 由此可见,分析结果如下: 1.引用顺序 DevIL.dll ILU.dll AspriseOCR.dll AspriseJTwain.dll (DevIL.dll 是算法库) 2.使用 GetSystemTime获得系统的当前时间,和注册表里的键值(二进制格式,估计是第一次使用时间)处理运算,如果时间过期就会弹出信息框提醒需要购买license. 3.注册表HKEY_LOCAL_MACHINE\SOFTWARE\Asprise OCR\ 有键值,试用版有键值现已将AspriseOCR.dll 破解,经过测试,将电脑时间调整到任何时间,都不会弹出信息框。 HKEY_LOCAL_MACHINE\SOFTWARE\Asprise OCR\ 如果以前运行过此类OCR,请将此注册表的键值先 删除。四个动态库可放到C:\WINDOWS\system32 下,也可以放到jre\bin下,或者是PATH 指定环境变量. 仅供个人学习使用。一份网站Asprise-OCR-Java原始Demo,一个破解文件 四个动态库。具体java Demo,参看原始Demo实例。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值