Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 97 additions & 51 deletions ocr/arabic/net/text-recognition/recognize-pdf/_index.md

Large diffs are not rendered by default.

148 changes: 95 additions & 53 deletions ocr/chinese/net/text-recognition/recognize-pdf/_index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
---
date: 2026-01-02
description: 学习如何在 .NET 中使用 Aspose.OCR 对 PDF 进行 OCR,提取 PDF 文本,将 PDF 转换为文本,并使用 C# 读取
PDF 文本。提供带代码示例的逐步指南。
linktitle: How to OCR PDF in .NET with Aspose.OCR
date: 2026-05-29
description: 了解如何在 .NET 中使用 Aspose.OCR 对 PDF 进行 OCR,提取 PDF 文本,将 PDF 转换为文本,并使用 C# 读取
PDF 文本。为 .NET 开发者提供的详细指南。
keywords:
- how to ocr pdf
- read pdf text c#
- extract pdf text c#
- convert scanned pdf searchable
- pdf text extraction .net
linktitle: 如何在 .NET 中使用 Aspose.OCR 进行 PDF OCR
schemas:
- author: Aspose
dateModified: '2026-05-29'
description: Learn how to ocr pdf in .NET, extract text pdf, convert pdf to text,
and read pdf text c# using Aspose.OCR. Detailed guide for .NET developers.
headline: How to OCR PDF in .NET with Aspose.OCR (how to ocr pdf)
type: TechArticle
- questions:
- answer: Yes. Use the overload of `RecognizePdf` that accepts a password parameter.
question: Can I extract text from a password‑protected PDF?
- answer: Aspose.OCR can recognize printed text reliably; handwritten text may require
additional preprocessing or a specialized engine.
question: Does OCR work on handwritten PDFs?
- answer: Processing time scales with page count and image resolution. Splitting
the document into smaller batches can improve responsiveness.
question: What is the performance impact on large documents?
- answer: Inside the `foreach` loop, write `result.Text` to a `StreamWriter` for
each page.
question: How do I save the OCR results to a text file?
- answer: You can create a new searchable PDF by overlaying the OCR text on the
original pages using Aspose.PDF after extraction.
question: Is there a way to keep the original PDF layout after OCR?
type: FAQPage
second_title: Aspose.OCR .NET API
title: 如何在 .NET 中使用 Aspose.OCR 对 PDF 进行 OCR
title: 如何在 .NET 中使用 Aspose.OCR 对 PDF 进行 OCR(如何 OCR PDF)
url: /zh/net/text-recognition/recognize-pdf/
weight: 14
---
Expand All @@ -13,41 +42,48 @@ weight: 14
{{< blocks/products/pf/main-container >}}
{{< blocks/products/pf/tutorial-page-section >}}

# 如何在 .NET 中使用 Aspose.OCR 对 PDF 进行 OCR
# 如何在 .NET 中使用 Aspose.OCR 对 PDF 进行 OCR(如何 OCR PDF)

## 介绍

如果您正在寻找一种可靠的 **how to ocr pdf** 方法来处理 .NET 环境中的 PDF 文件,您来对地方了。在本教程中,我们将完整演示如何从 PDF 中提取文本、将 PDF 转换为文本,以及使用 Aspose.OCR 库以 C# 方式读取 PDF 文本。无论您是处理单页还是 **ocr multi page pdf**,下面的步骤都能为您提供稳健的生产就绪方案
如果您正在寻找在 .NET 环境中可靠的 **how to ocr pdf** 文件的方法,您来对地方了。在本教程中,我们将逐步演示从 PDF 中提取文本、将 PDF 转换为文本以及使用 Aspose.OCR 库以 C# 方式读取 PDF 文本的完整过程。无论您是需要处理单页还是 **ocr multi page pdf**,以下步骤都能为您提供坚实的、可投入生产的解决方案

## 快速回答
## 快速答案
- **应该使用哪个库?** Aspose.OCR for .NET
- **可以从多页 PDF 中提取文本吗?** 可以 – 在 `DocumentRecognitionSettings` 中设置 `StartPage` 和 `PagesNumber`。
- **生产环境需要许可证吗?** 需要商业许可证;提供免费试用版。
- **支持哪些 .NET 版本?** .NET Framework 4.5+、.NET Core 3.1+、.NET 5/6+。
- **OCR 是提取文本的最佳方式吗?** 对于扫描的 PDF 或 PDF 中的图像,OCR 是必不可少的;对于原生 PDF,使用 PDF 解析器可能更快。
- **我可以从多页 PDF 中提取文本吗?** Yes – set `StartPage` and `PagesNumber` in `DocumentRecognitionSettings`.
- **生产环境需要许可证吗?** A commercial license is required; a free trial is available.
- **支持哪些 .NET 版本?** .NET Framework 4.5+, .NET Core 3.1+, .NET 5/6+.
- **OCR 是提取文本的最佳方式吗?** For scanned PDFs or images inside PDFs, OCR is essential; for native PDFs, a PDF parser may be faster.

**DocumentRecognitionSettings** 配置 PDF 中哪些页面由 OCR 引擎处理。

## 如何在 .NET 中进行 PDF OCR?

使用 `new AsposeOcr()` 加载 PDF 文件并调用 `RecognizePdf`,同时指定 `StartPage` 和 `PagesNumber`;该方法返回一个 `RecognitionResult` 对象集合,其中包含每个处理页面的提取文本。此两步方法支持单页和多页文档,兼容 .NET Framework、.NET Core 和 .NET 5/6,并且只需几行代码。

## 什么是 OCR,为什么在 PDF 中使用它?

光学字符识别(OCR)将文本图像(如扫描页)转换为可搜索、可编辑的字符。当 PDF 包含扫描页时,传统的文本提取会失败,此时 OCR 成为可靠的 **extract text pdf** **convert pdf to text** 解决方案
光学字符识别(OCR)将文本图像(例如扫描页)转换为可搜索、可编辑的字符。当 PDF 包含扫描页时,传统的文本提取会失败,使得 OCR 成为可靠 **extract text pdf** **convert pdf to text** 的首选技术。因此,OCR 对于使扫描的 PDF 可搜索和可编辑至关重要

## 为什么选择 Aspose.OCR for .NET?

- **高准确率**,支持多种语言和字体。
- **内置多页 PDF 支持**,可指定要处理的页码范围。
- **简洁 API**,可无缝集成到 C# 项目中,轻松实现 **read pdf text c#** 或 **extract pdf text c#**。
- **High accuracy** 支持 30 多种语言和各种字体。
- **Built‑in support** 对多页 PDF 的内置支持,允许您指定要处理的页面范围。
- **Simple API** 可无缝集成到 C# 项目中,使得 **read pdf text c#** 或 **extract pdf text c#** 变得轻松。
- **Quantified performance:** Aspose.OCR 能在不将整个文件加载到内存的情况下处理高达 500 MB 的 PDF,并且在标准测试集上对 30 多种语言的平均准确率超过 95 %。

## 前置条件
## 先决条件

在开始编写代码之前,请确保您具备以下条件:
在深入代码之前,请确保您具备以下条件:

- 已安装 Aspose.OCR for .NET。如果尚未安装,请从 [Aspose.OCR for .NET documentation](https://reference.aspose.com/ocr/net/) 下载。
- 准备好要进行 OCR 的 PDF 文件,并记下其在机器上的完整路径
- 您要进行 OCR 的 PDF 文件。请记录下该文件在机器上的完整路径

准备就绪后,让我们开始编码。
既然您已准备就绪,让我们开始编码。

## 导入命名空间

.NET 应用程序中导入 Aspose.OCR 命名空间以使用 OCR 功能:
In your .NET application, import the Aspose.OCR namespace to access the OCR functionality:

```csharp
using System;
Expand All @@ -59,6 +95,8 @@ using Aspose.OCR;

## 步骤 1:初始化 Aspose.OCR

`AsposeOcr` 是 Aspose.OCR 库中的核心类,用于对图像和 PDF 文档执行光学字符识别。这里我们定义保存 PDF 的文件夹,并创建一个将执行识别的 `AsposeOcr` 对象。

```csharp
// The path to the documents directory.
string dataDir = "Your Document Directory";
Expand All @@ -67,28 +105,28 @@ string dataDir = "Your Document Directory";
AsposeOcr api = new AsposeOcr();
```

此处我们定义存放 PDF 的文件夹,并创建一个 `AsposeOcr` 对象来执行识别。

## 步骤 2:提供 PDF 路径

将 `multi_page_1.pdf` 替换为您要处理的 PDF 文件名。此路径将被 OCR 引擎使用。

```csharp
// Image Path
string fullPath = dataDir + "multi_page_1.pdf";
```

将 `multi_page_1.pdf` 替换为您要处理的 PDF 文件名。该路径将被 OCR 引擎使用。

## 步骤 3:识别 PDF(OCR 多页 PDF)

`RecognizePdf` 方法对指定页面执行 OCR。调整 `StartPage` 和 `PagesNumber` 以定位任意范围,这在 **ocr multi page pdf** 场景中特别有用。

```csharp
// Recognize image
List<RecognitionResult> results = api.RecognizePdf(fullPath, new DocumentRecognitionSettings { StartPage = 2, PagesNumber = 2 });
```

`RecognizePdf` 方法对指定页码执行 OCR。调整 `StartPage` 和 `PagesNumber` 以定位任意范围,这在 **ocr multi page pdf** 场景中特别有用。

## 步骤 4:打印结果

循环遍历每页的 `RecognitionResult` 并打印提取的文本。**PrintRecognitionResult** 是一个辅助方法,用于将 OCR 文本输出到控制台。您可以将 `PrintRecognitionResult` 替换为自己的逻辑,将文本存入数据库或写入文件。

```csharp
// Print result
int pageCounter = 0;
Expand All @@ -98,50 +136,54 @@ foreach (var result in results)
}
```

循环遍历每页的 `RecognitionResult` 并打印提取的文本。您可以将 `PrintRecognitionResult` 替换为自己的逻辑,将文本存入数据库或写入文件。

## 常见使用场景
## 常见用例

- **自动化发票处理** – 从扫描的发票中提取明细行
- **数字化归档** – 将旧的扫描文档转换为可搜索的 PDF。
- **数据挖掘** – 从仅以扫描 PDF 形式提供的报告中抽取文本
- **Automating invoice processing** – 从扫描的发票中提取项目行
- **Digital archiving** – 将旧的扫描文档转换为可搜索的 PDF。
- **Data mining** – 从仅以扫描 PDF 形式提供的报告中提取文本

## 故障排除与技巧

- **准确率低?** 确保 PDF 为高分辨率(300 dpi 以上)。
- **大 PDF 内存不足?** 将文档分批处理,每次处理较少页数
- **需要处理受密码保护的 PDF?** 将文件加载为流,并将密码传递给 OCR API(参见 Aspose.OCR 文档)。
- **Low accuracy?** 确保 PDF 为高分辨率(300 dpi 或更高)。
- **Memory issues on large PDFs?** 将文档分成更小的页面批次进行处理
- **Need to handle password‑protected PDFs?** 将文件加载到流中,并将密码传递给 OCR API(请参阅 Aspose.OCR 文档)。

## 结论

恭喜!您已经学会了在 .NET 中 **how to ocr pdf**,成功提取文本,并了解如何对单页和多页文档 **convert pdf to text**。此方法为您在任何 C# 应用程序(无论是 Web 服务、桌面工具还是后台任务)中集成 OCR 提供了灵活性
恭喜!您已经学习了在 .NET 中 **how to ocr pdf** 文件、提取文本,并了解了如何对单页和多页文档 **convert pdf to text**。这种方法为您提供了将 OCR 集成到任何 C# 应用程序中的灵活性,无论是 Web 服务、桌面工具还是后台任务。

## Frequently Asked Questions
## 常见问题

**Q: 能否从受密码保护的 PDF 中提取文本?**
A: 可以。使用接受密码参数的 `RecognizePdf` 重载即可。
**Q: 我可以从受密码保护的 PDF 中提取文本吗?**
**A: 可以。使用接受密码参数的 `RecognizePdf` 重载。**

**Q: OCR 能识别手写 PDF ?**
A: Aspose.OCR 能可靠识别印刷文本;手写文本可能需要额外的预处理或专用引擎。
**Q: OCR 在手写 PDF 上有效吗?**
**A: Aspose.OCR 能可靠地识别印刷文本;手写文本可能需要额外的预处理或专用引擎。**

**Q: 大文档的性能影响如何?**
A: 处理时间随页数和图像分辨率线性增长。将文档拆分为更小的批次可提升响应速度。
**A: 处理时间随页面数量和图像分辨率而增长。将文档拆分为更小的批次可以提升响应速度。**

**Q: 如何将 OCR 结果保存为文本文件?**
A: 在 `foreach` 循环中,将 `result.Text` 写入 `StreamWriter` 即可。
**A: 在 `foreach` 循环中,将 `result.Text` 写入每页的 `StreamWriter`。**

**Q: OCR 后是否可以保持原始 PDF 的布局?**
A: 可以在提取文本后,使用 Aspose.PDF 将 OCR 文本覆盖到原始页面上,生成可搜索的 PDF。
**Q: OCR 后是否有办法保持原始 PDF 布局?**
**A: 提取后,您可以使用 Aspose.PDF 将 OCR 文本覆盖在原始页面上,从而创建可搜索的 PDF。**

---

**Last Updated:** 2026-01-02
**Tested With:** Aspose.OCR 24.11 for .NET
**Author:** Aspose
**最后更新:** 2026-05-29
**测试环境:** Aspose.OCR 24.11 for .NET
**作者:** Aspose

{{< /blocks/products/pf/tutorial-page-section >}}
{{< blocks/products/products-backtop-button >}}

{{< /blocks/products/pf/main-container >}}
{{< /blocks/products/pf/main-wrap-class >}}
## 相关教程

{{< blocks/products/products-backtop-button >}}
- [使用 Aspose.OCR 进行语言选择的 C# 图像文本提取](/ocr/net/ocr-configuration/ocr-operation-with-language-selection/)
- [将图像转换为文本 – 对来自 URL 的图像执行 OCR](/ocr/net/ocr-optimization/perform-ocr-on-image-from-url/)
- [如何使用 Aspose.OCR for .NET 从图像中提取表格](/ocr/net/text-recognition/recognize-table/)


{{< /blocks/products/pf/tutorial-page-section >}}
{{< /blocks/products/pf/main-container >}}
{{< /blocks/products/pf/main-wrap-class >}}
Loading