Class PdfForm

信息

代表 Documentize.PdfForm 组件。用于扁平化、提取表单数据。也可以获取字段名称。

代表 Documentize.PdfForm 组件。用于扁平化、提取表单数据。
也可以获取字段名称。

public static class PdfForm

继承

object ←
PdfForm

继承成员

方法

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
PdfForm.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
PdfForm.Extract(options);

异常

ArgumentException
如果未设置 options。

Flatten(FlattenFieldsOptions)

在 PDF 文档中扁平化字段。

public static ResultContainer Flatten(FlattenFieldsOptions options)

参数

返回

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

示例

该示例演示如何在 PDF 文件中扁平化字段。

// Create FlattenFieldsOptions object to set instructions
var options = new FlattenFieldsOptions();
// 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_pdf_file.pdf"));
// Perform the process
PdfForm.Flatten(options);

该示例演示如何在 PDF 文件中扁平化字段并跳过第一个字段。

// Get Fields Names
var fieldNames = PdfForm.GetNames(new GetFieldNamesOptions("path_to_your_pdf_file.pdf"));
// Create FlattenFieldsOptions object to set instructions
var options = new FlattenFieldsOptions();
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Skip 1 field.
options.SkipFields.Add(fieldNames[0]);
// Perform the process
PdfForm.Flatten(options);

异常

ArgumentException
如果未设置 options。

GetNames(GetFieldNamesOptions)

检索 PDF 文档中所有交互式表单字段的名称。

public static List<string> GetNames(GetFieldNamesOptions options)

参数

  • options GetFieldNamesOptions:指定输入源(文件路径或流)以及操作指令的 Documentize.GetFieldNamesOptions 实例。

返回

List<string>
一个字符串列表,表示在 PDF 文档中找到的字段名称。

示例

该示例演示如何以最简方式从 PDF 文件获取字段名称。

// Get field names
var fieldNames = PdfForm.GetNames(new GetFieldNamesOptions("path_to_your_pdf_file.pdf"));

该示例演示如何从 PDF 文件获取字段名称。

// Create GetFieldNamesOptions object to set instructions
var options = new GetFieldNamesOptions("path_to_your_pdf_file.pdf");
// Perform the process and get names
var fieldNames = PdfForm.GetNames(options);

该示例演示如何从 PDF 流获取字段名称。

// Prepare input stream
using var inputStream = File.OpenRead("path_to_your_pdf_file.pdf");
// Get field names
var fieldNames = PdfForm.GetNames(new GetFieldNamesOptions(inputStream));

该示例演示如何设置 Documentize.GetFieldNamesOptions 类的 Input 属性。
这在循环操作中非常有用,无需创建新实例。

var options = new GetFieldNamesOptions();
// Set input from a file
options.Input = new FileData("path_to_your_pdf_file.pdf");
// Or set input from a stream
// options.Input = new StreamData(stream);
var results = PdfForm.GetNames(options);

Remove(RemoveFieldsOptions) : 从 PDF 文档中移除字段。

public static ResultContainer Remove(RemoveFieldsOptions options)

参数

返回

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

示例

该示例演示如何从 PDF 文件中移除字段。

// Create RemoveFieldsOptions object to set instructions
var options = new RemoveFieldsOptions();
// 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_pdf_file.pdf"));
// Perform the process
PdfForm.Remove(options);

异常

ArgumentException
如果未设置 options。

命名空间: Documentize
程序集: Documentize.dll

 中文