PDFField

PDFField

PDFField类,表示PDF表单域。

Constructor

new PDFField()

Example
let pdfDoc; // PDFDoc实例
let pdfForm = await pdfDoc.loadPDFForm();
let pdfField = await pdfForm.getField('fieldName');

Methods

(async) describeFieldFlags() → {Promise.<FieldFlagOptions>}

Description:
  • 获取表单域的各个标志属性值。
Returns:
返回一个对象,描述表单域的各个标志属性及其布尔值。
Type
Promise.<FieldFlagOptions>

(async) getAlignment() → {Promise.<number>}

Description:
  • 获取表单域的对齐方式。
Returns:
对齐方式,参考 Constants.Alignment
Type
Promise.<number>

(async) getAlternateName() → {Promise.<string>}

Description:
  • 获取表单域的备用名称。
Returns:
Type
Promise.<string>

getBorderColor()

Description:
  • 获取表单域的边框颜色(不支持签名域)。在调用此函数之前加载所有相对注释,否则将返回错误的值。
Deprecated:

getBorderStyle()

Description:
  • 获取表单域的边框样式。在调用此函数之前加载所有相对注释,否则将返回错误的值。
Deprecated:

getControlByIndex()

Description:
  • 根据索引获取指定的表单控件。
Deprecated:

getControlsCount()

Description:
  • 获取表单控件的计数。
Deprecated:

getFillColor()

Description:
  • 获取表单域的填充颜色。在调用此函数之前加载所有相对注释,否则将返回错误的值。
Deprecated:

getFlags() → {number}

Description:
  • 获取表单域 flags。
Deprecated:
Returns:
flags 值,参考 Constants.Field_Flag,可为组合值。
Type
number

(async) getMappingName() → {Promise.<string>}

Description:
  • 获取映射名称。在导出交互式表单数据时使用。
Returns:
Type
Promise.<string>

(async) getMaxLength() → {Promise.<number>}

Description:
  • 获取文本类型表单域的最大长度。
Returns:
Type
Promise.<number>

getName() → {string}

Description:
  • 获取表单域名称。
Returns:
字段名称。
Type
string

getOptions() → {Array.<PDFField.BasicOptions>}

Description:
  • 获取列表框或组合框的选项。
Returns:
选项数组。
Type
Array.<PDFField.BasicOptions>

getType() → {Constants.Field_Type}

Description:
  • 获取表单域的类型。
Returns:
表单域的类型。
Type
Constants.Field_Type

(async) getValue() → {Promise.<string>}

Description:
  • 获取表单域值。
Returns:
Type
Promise.<string>

(async) getWidget(indexopt) → {Promise.<Widget>}

Description:
  • 获取表单域的注释。
Parameters:
Name Type Attributes Default Description
index number <optional>
0 注释索引,默认值为0。
Returns:
表单域的注释对象。
Type
Promise.<Widget>

(async) getWidgetsCount() → {Promise.<number>}

Description:
  • 获取表单域的注释数量。
Returns:
表单域的注释数量。
Type
Promise.<number>

(async) setAlignment(alignment) → {Promise.<void>}

Description:
  • 设置表单域的对齐方式。(不支持签名域)
Parameters:
Name Type Description
alignment number 对齐方式,参考 Constants.Alignment
Returns:
Type
Promise.<void>

(async) setAlternateName(alternateName) → {Promise.<void>}

Description:
  • 设置表单域的备用名称。此名称会在 UI 提示/错误/状态消息中代替真实字段名显示,也可用于辅助功能场景。
Parameters:
Name Type Description
alternateName string 备用名称。
Returns:
Type
Promise.<void>

setBorderColor()

Description:
  • 设置表单域的边框颜色(不支持签名域)。在调用此函数之前加载所有相对注释,否则将返回错误的值。
Deprecated:

setBorderStyle()

Description:
  • 设置表单域的边框样式。在调用此函数之前加载所有相对注释,否则将返回错误的值。
Deprecated:

setFillColor()

Description:
  • 设置表单域的填充颜色(不支持签名域)。在调用此函数之前加载所有相对注释,否则将返回错误的值。
Deprecated:

(async) setFlags(flags) → {Promise.<void>}

Description:
  • 设置表单域 flags。
Deprecated:
Parameters:
Name Type Description
flags number Flags 值,参考 Constants.Field_Flag,可为组合值。
Returns:
Type
Promise.<void>

(async) setMappingName(mappingName) → {Promise.<void>}

Description:
  • 设置映射名称(不支持签名域)。该名称在导出交互式表单域数据时使用。
Parameters:
Name Type Description
mappingName string 映射名称。
Returns:
Type
Promise.<void>

(async) setMaxLength(maxLength) → {Promise.<void>}

Description:
  • 设置文本类型表单域的最大长度。
Parameters:
Name Type Description
maxLength number 最大字符数。
Returns:
Type
Promise.<void>

(async) setOptions(options) → {Promise.<void>}

Description:
  • 设置列表框或组合框的选项(项目)。仅适用于列表框或组合框类型字段。
Example
let options = [{
  label: 'test',
  value: "111",
  selected: false,
  defaultSelected: false,
},{
  label: 'label',
  value: "222",
  selected: false,
  defaultSelected: true,
}]
pdfField.setOptions(options);
Parameters:
Name Type Description
options Array.<PDFField.BasicOptions> 选项数据列表。
Returns:
Type
Promise.<void>

(async) setValue(value) → {Promise.<void>}

Description:
  • 设置表单域值。
Parameters:
Name Type Description
value string 值。
Returns:
Type
Promise.<void>

(async) updateFlagByOptions(options) → {Promise.<void>}

Description:
  • 更新表单域的标志。
Example
// 将字段设置为只读和必填
await pdfField.updateFlagByOptions({
  readonly: true,
  required: true,
});
Parameters:
Name Type Description
options FieldFlagOptions 标志选项对象,包含需要更新的标志属性。
Returns:
Type
Promise.<void>

Type Definitions

BasicOptions

Properties:
Name Type Description
label string 显示的选项值。
value string 选项值。
selected boolean 是否已选中。
defaultSelected boolean 是否默认选中。
Type:
  • Object