HTML JPG PDF XML DOCX
  Product Family
PDF

在 .NET SDK 中解析 PDF 以提取文本

用于解析 PDF 文档以通过服务器端 .NET API 提取文本的 API。

Get Started

如何使用 Cloud .NET SDK 解析 PDF 文档以提取文本

为了通过 Cloud .NET SDK 解析 PDF 文档以提取文本,我们将使用 Aspose.PDF Cloud .NET SDK 此 Cloud .NET SDK 允许您轻松构建基于云的 PDF 创建、编辑和转换应用程序,支持 C#、ASP.NET 或其他 .NET 语言的各种云平台。打开 NuGet 包管理器,搜索 Aspose.PDF Cloud 并安装。您还可以从包管理器控制台使用以下命令。

包管理器控制台命令


     
    PM> Install-Package Aspose.Pdf-Cloud
     
     

使用 .NET SDK 解析 PDF 以提取文本的步骤

Aspose.PDF Cloud 开发人员可以轻松解析 PDF 文档以提取文本。开发人员只需几行代码即可完成。

  1. 使用您的应用程序秘密和密钥创建新的配置对象
  2. 创建一个对象以连接到云 API
  3. 上传您的文档文件
  4. 使用 GetDocumentTextBoxFieldsAsync 函数在云存储中解析 PDF 文档以提取文本
  5. 检查响应并记录结果
  6. 如果操作成功,打印提取的文本
 

此示例代码显示解析 PDF 文档以提取文本


using Aspose.Pdf.Cloud.Sdk.Model;

namespace Parser
{
    public class GetTextBoxes
    {
        public static async Task Extract(string documentName, string remoteFolder)
        {
		// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
		pdfApi = new PdfApi(AppSecret, AppSid);

                using (var file = File.OpenRead(Path.Combine(localFolder, documentName)))
		{ // Upload the local PDF to cloud storage folder name.
                    FilesUploadResult uploadResponse = await pdfApi.UploadFileAsync(Path.Combine(remoteFolder, documentName), documentName);
                    Console.WriteLine(uploadResponse.Uploaded[0]);
                }

                // Parse PDF to extract text boxes in cloud storage.
                TextBoxFieldsResponse response = await pdfApi.GetDocumentTextBoxFieldsAsync(documentName, folder: remoteFolder);

                // Checks the response and logs the result.
                if (response == null)
                    Console.WriteLine("GetTextBoxes(): Unexpected error!");
                else if (response.Code < 200 || response.Code > 299)
                    Console.WriteLine("GetTextBoxes():  Failed to receive TextBox fields from the document.");
                else
                { // Show text boxes.
                    Console.WriteLine("GetTextBoxes(): TextBox fields successfully received from the document '{0}.", documentName);
                    foreach (TextBoxField textBox in response.Fields.List)
                    {
                        Console.WriteLine(textBox.ToString());
                    }
                }
            }
        }
    }
 

通过 .NET SDK 处理 PDF 中的文本解析

通过解析 PDF 文档以提取文本,您可以根据需要修改文本框字段的内容。这可以保持文档中文本的位置,同时节省时间并减少手动工作。 使用 Aspose.PDF Cloud .NET SDK 解析 PDF 文档以提取文本。

使用我们的 .NET SDK,您可以

  • 以文本或图像格式添加 PDF 文档的页眉和页脚。
  • 将表格和文本或图像水印添加到 PDF 文档中。
  • 将多个 PDF 文档追加到现有文件。
  • 处理 PDF 附件、注释和表单字段。
  • 对 PDF 文档应用加密或解密并设置密码。
  • 从页面或整个 PDF 文档中删除所有水印和表格。
  • 按 ID 删除 PDF 文档中的特定水印或表格。
  • 替换 PDF 页面上的单个或多个文本实例或整个文档中的文本。
  • 广泛支持将 PDF 文档转换为各种其他文件格式。
  • 提取 PDF 文件的各种元素并优化 PDF 文档。
  • 您可以尝试我们的免费应用程序来测试功能。

  •