Class PdfExtractor

信息

表示 Documentize.PdfExtractor 组件。用于从 PDF 文档中提取文本、图像、表单数据、属性(元数据)。

public static class PdfExtractor

Inheritance

objectPdfExtractor

Inherited Members

方法

Extract(ExtractTextOptions)

从 PDF 文档中提取文本。

public static string Extract(ExtractTextOptions options)

参数

返回值

string : 提取的文本。

示例

示例演示如何从 PDF 文件中提取文本内容。

// Create ExtractTextOptions object to set input file path
var options = new ExtractTextOptions("path_to_your_pdf_file.pdf");
// Perform the process and get the extracted text
var textExtracted = PdfExtractor.Extract(options);

示例演示如何从 PDF 流中提取文本内容。

// Create ExtractTextOptions object to set input stream
var stream = File.OpenRead("path_to_your_pdf_file.pdf");
var options = new ExtractTextOptions(stream);
// Perform the process and get the extracted text
var textExtracted = PdfExtractor.Extract(options);

示例演示如何使用 TextFormattingMode 提取 PDF 文档的文本内容。

// Create ExtractTextOptions object to set input file path and TextFormattingMode
var options = new ExtractTextOptions("path_to_your_pdf_file.pdf", TextFormattingMode.Pure);
// Perform the process and get the extracted text
var textExtracted = PdfExtractor.Extract(options);

示例演示如何以最简洁的方式从 PDF 文件提取文本。

// Perform the process and get the extracted text
var textExtracted = PdfExtractor.Extract(new ExtractTextOptions("path_to_your_pdf_file.pdf", TextFormattingMode.Pure));

异常

ArgumentException

如果未设置 options。

Extract(ExtractImagesOptions)

从 PDF 文档中提取图像。

public static ResultContainer Extract(ExtractImagesOptions options)

参数

返回值

ResultContainer : 包含操作结果的对象。

示例

示例演示如何从 PDF 文档中提取图像。

// Create ExtractImagesOptions to set instructions
var options = new ExtractImagesOptions();
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryData("path_to_results_directory"));
// Perform the process
var results = PdfExtractor.Extract(options);
// Get path to image result
var imageExtracted = results.ResultCollection[0].ToFile();

示例演示如何将图像提取到流中(不使用文件夹)。

// Create ExtractImagesOptions to set instructions
var options = new ExtractImagesOptions();
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Not set output - it will write results to streams
// Perform the process
var results = PdfExtractor.Extract(options);
// Get Stream
var ms = results.ResultCollection[0].ToStream();
// Copy data to file for demo
ms.Seek(0, SeekOrigin.Begin);
using (var fs = File.Create("test_file.png"))
{
    ms.CopyTo(fs);
}

异常

ArgumentException

如果未设置 options。

Extract(ExtractFormDataToDsvOptions)

从 PDF 文档中提取表单数据。

public static ResultContainer Extract(ExtractFormDataToDsvOptions options)

参数

返回值

ResultContainer : 包含操作结果的对象。

示例

示例演示如何将表单值导出为 CSV 文件。

// Create ExtractFormDataToDsvOptions object to set instructions
var options = new ExtractFormDataToDsvOptions(',', true);
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_csv_file.csv"));
// Perform the process
PdfExtractor.Extract(options);

示例演示如何将表单值导出为 TSV 文件并设置属性。

// Create ExtractFormDataToDsvOptions object to set instructions
var options = new ExtractFormDataToDsvOptions();
//Set Delimiter
options.Delimiter = '\t';
//Add Field Names to result
options.AddFieldName = true;
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_csv_file.tsv"));
// Perform the process
PdfExtractor.Extract(options);

异常

ArgumentException

如果未设置 options。

Extract(ExtractPropertiesOptions)

从 PDF 文档中提取属性。

public static PdfProperties Extract(ExtractPropertiesOptions options)

参数

返回值

PdfProperties : 包含操作结果的对象。

示例

示例演示如何从 PDF 文件中提取属性(文件名、标题、作者、主题、关键字、创建时间、修改时间、应用程序、PDF 生成器、页数)。

// Create ExtractPropertiesOptions object to set input file
var options = new ExtractPropertiesOptions("path_to_your_pdf_file.pdf");
// Perform the process and get Properties
var pdfProperties = PdfExtractor.Extract(options);
var filename = pdfProperties.FileName;
var title = pdfProperties.Title;
var author = pdfProperties.Author;
var subject = pdfProperties.Subject;
var keywords = pdfProperties.Keywords;
var created = pdfProperties.Created;
var modified = pdfProperties.Modified;
var application = pdfProperties.Application;
var pdfProducer = pdfProperties.PdfProducer;
var numberOfPages = pdfProperties.NumberOfPages;

示例演示如何从 PDF 流中提取属性(标题、作者、主题、关键字、创建时间、修改时间、应用程序、PDF 生成器、页数)。

// Create ExtractPropertiesOptions object to set input stream
var stream = File.OpenRead("path_to_your_pdf_file.pdf");
var options = new ExtractPropertiesOptions(stream);
// Perform the process and get Properties
var pdfProperties = PdfExtractor.Extract(options);
var title = pdfProperties.Title;
var author = pdfProperties.Author;
var subject = pdfProperties.Subject;
var keywords = pdfProperties.Keywords;
var created = pdfProperties.Created;
var modified = pdfProperties.Modified;
var application = pdfProperties.Application;
var pdfProducer = pdfProperties.PdfProducer;
var numberOfPages = pdfProperties.NumberOfPages;

示例演示如何以最简洁的方式从 PDF 文件提取属性。

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

异常

ArgumentException

如果未设置 options。

Namespace: Documentize Assembly: Documentize.dll

 中文