PDF Extractor

提取文本

使用 Documentize 的 .NET 工具准确地从 PDF 中提取文本——轻松检索、处理和分析内容。

提取图像

在 .NET 应用程序中轻松从 PDF 文档中提取图像

提取属性 / 元数据

使用 Documentize 在 C#/.NET 中准确提取 PDF 的元数据

导出表单数据

使用 C#/.NET 从 PDF 表单(AcroForms)中提取并导出数据到 CSV 等其他格式

PDF Extractor 的子部分

提取文本

The Documentize PDF Extractor for .NET 简化了从 PDF 文档中提取文本的过程。无论您需要纯文本、原始文本还是普通文本,此插件都能高效提取文本,并根据需要保留或省略格式。

如何从 PDF 中提取文本

要从 PDF 文档中提取文本,请遵循以下步骤:

  1. 创建 ExtractTextOptions 实例以配置提取选项。
  2. 使用 AddInput 方法添加输入 PDF 文件。
  3. 运行 Extract 方法进行文本提取。
  4. 通过 ResultContainer.ResultCollection 访问提取的文本。
1// Create ExtractTextOptions object to set instructions
2var options = new ExtractTextOptions();
3// Add input file path
4options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
5// Perform the process
6var results = PdfExtractor.Extract(options);
7// Get the extracted text from the ResultContainer object
8var textExtracted = results.ResultCollection[0].ToString();

文本提取模式

ExtractTextOptions 提供三种提取模式,根据您的需求提供灵活性。

  1. Pure Mode:保留原始格式,包括空格和对齐。
  2. Raw Mode:提取不带格式的文本,适用于原始数据处理。
  3. Flatten Mode:通过坐标将 PDF 内容表示为定位的文本片段。
1// Create ExtractTextOptions object to set TextFormattingMode
2var options = new ExtractTextOptions(TextFormattingMode.Pure);
3// Add input file path
4options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
5// Perform the process
6var results = PdfExtractor.Extract(options);
7// Get the extracted text from the ResultContainer object
8var textExtracted = results.ResultCollection[0].ToString();

关键特性:

  • Pure Mode:提取文本并保留其原始格式。
  • Raw Mode:提取不含任何格式的文本。
  • Flatten Mode:提取不含特殊字符或格式的文本。

提取图像

The Documentize PDF Extractor for .NET plugin enables you to effortlessly extract images from PDF documents. It scans your PDF files, identifies embedded images, and extracts them while maintaining their original quality and format. This tool enhances the accessibility of visual content and streamlines the process of retrieving images from PDFs.

如何从 PDF 中提取图像

要从 PDF 文件中提取图像,请按照以下步骤操作:

  1. 创建 ExtractImagesOptions 类的实例。
  2. 使用 AddInput 方法将输入文件路径添加到选项中。
  3. 使用 AddOutput 方法设置图像的输出目录路径。
  4. 使用插件执行图像提取过程。
  5. 从结果容器中获取提取的图像。
 1// Create ExtractImagesOptions to set instructions
 2var options = new ExtractImagesOptions();
 3// Add input file path
 4options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
 5// Set output Directory path
 6options.AddOutput(new DirectoryDataSource("path_to_results_directory"));
 7// Perform the process
 8var results = PdfExtractor.Extract(options);
 9// Get path to image result
10var imageExtracted = results.ResultCollection[0].ToFile();

将 PDF 文件中的图像提取到流而不使用文件夹

The PdfExtractor plugin supports saving to streams, which allows you to extract images from PDF files into streams without using temporary folders.

 1// Create ExtractImagesOptions to set instructions
 2var options = new ExtractImagesOptions();
 3// Add input file path
 4options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
 5// Not set output - it will write results to streams
 6// Perform the process
 7var results = PdfExtractor.Extract(options);
 8// Get Stream
 9var ms = results.ResultCollection[0].ToStream();
10// Copy data to file for demo
11ms.Seek(0, SeekOrigin.Begin);
12using (var fs = File.Create("test_file.png"))
13{
14    ms.CopyTo(fs);
15}

关键特性:

  • 提取嵌入的图像:识别并提取 PDF 文档中的图像。
  • 保留图像质量:确保提取的图像保持原始质量。
  • 灵活的输出:将提取的图像保存为您偏好的格式或位置。

提取属性 / 元数据

The Documentize PDF Extractor for .NET 简化了从 PDF 文档中提取元数据的过程。
可供您使用的属性包括:标题、作者、主题、关键字、页数。

How to Extract Metadata from PDF file

示例演示了如何从 PDF 文件中提取属性(标题、作者、主题、关键字、页数)。
要从 PDF 文档中提取元数据,请按照以下步骤操作:

  1. 创建 ExtractPropertiesOptions 实例以配置提取选项和输入 PDF 文件。
  2. 调用 PdfExtractorExtract 方法进行提取。
  3. 使用 PdfProperties 访问提取的属性。
1// Create ExtractPropertiesOptions object to set input file
2var options = new ExtractPropertiesOptions("path_to_your_pdf_file.pdf");
3// Perform the process and get Properties
4var pdfProperties = PdfExtractor.Extract(options);
5var title = pdfProperties.Title;
6var author = pdfProperties.Author;
7var subject = pdfProperties.Subject;
8var keywords = pdfProperties.Keywords;
9var numberOfPages = pdfProperties.NumberOfPages;

How to Extract Metadata from PDF stream

您可以自行决定如何打开流。

 1// Create ExtractPropertiesOptions object to set input stream
 2var stream = File.OpenRead("path_to_your_pdf_file.pdf");
 3var options = new ExtractPropertiesOptions(stream);
 4// Perform the process and get Properties
 5var pdfProperties = PdfExtractor.Extract(options);
 6var title = pdfProperties.Title;
 7var author = pdfProperties.Author;
 8var subject = pdfProperties.Subject;
 9var keywords = pdfProperties.Keywords;
10var numberOfPages = pdfProperties.NumberOfPages;

How to Extract Metadata from PDF file in the shortest possible style

1// Perform the process and get Properties
2var pdfProperties = PdfExtractor.Extract(new ExtractPropertiesOptions("path_to_your_pdf_file.pdf"));

Key Features:

  • Available metadata: Title, Author, Subject, Keywords, Number of Pages.

导出表单数据

The Documentize PDF Extractor for .NET 插件提供了一种无缝的方法,将 PDF 表单(AcroForms)中的数据提取并导出为 CSV 等其他格式。此动态工具简化了检索表单字段值的过程,便于轻松进行数据管理、传输和分析。

如何从 PDF 导出表单数据

要将 PDF 表单数据导出为 CSV,请按照以下步骤操作:

  1. 创建 ExtractImagesOptions 类的实例。
  2. 使用 FormExporterValuesToCsvOptions 类定义导出选项。
  3. 添加输入 PDF 文件并指定输出 CSV 文件。
  4. 运行 Extract 方法执行导出。
1// Create ExtractFormDataToDsvOptions object to set instructions
2var options = new ExtractFormDataToDsvOptions(',', true);
3// Add input file path
4options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
5// Set output file path
6options.AddOutput(new FileDataSource("path_to_result_csv_file.csv"));
7// Perform the process
8PdfExtractor.Extract(options);

关键特性:

  • 导出表单数据:将 PDF 表单(AcroForms)中的数据提取为 CSV 或其他格式。
  • 数据过滤:使用谓词根据字段类型或页码等条件过滤特定表单字段进行导出。
  • 灵活的输出:保存导出的数据以供分析,或转移到电子表格、数据库或其他文档格式。
 中文