PDFField
Represents a field of a PDFForm.
This class is effectively abstract. All fields in a PDFForm will actually be an instance of a subclass of this class.
Note that each field in a PDF is represented by a single field object. However, a given field object may be rendered at multiple locations within the document (across one or more pages). The rendering of a field is controlled by its widgets. Each widget causes its field to be displayed at a particular location in the document.
Most of the time each field in a PDF has only a single widget, and thus is only rendered once. However, if a field is rendered multiple times, it will have multiple widgets - one for each location it is rendered.
This abstraction of field objects and widgets is defined in the PDF specification and dictates how PDF files store fields and where they are to be rendered.
Hierarchy
PDFField
Index
Properties
Methods
- disableExporting
- disableReadOnly
- disableRequired
- enableExporting
- enableReadOnly
- enableRequired
- getName
- isExported
- isReadOnly
- isRequired
Properties
acroField
• acroField: PDFAcroTerminal
Defined in api/form/PDFField.ts:86
The low-level PDFAcroTerminal wrapped by this field.
doc
• doc: PDFDocument
Defined in api/form/PDFField.ts:92
The document to which this field belongs.
ref
• ref: PDFRef
Defined in api/form/PDFField.ts:89
The unique reference assigned to this field within the document.
Methods
disableExporting
▸ disableExporting(): void
Defined in api/form/PDFField.ts:247
Indicate that this field's value should not be exported when the form is submitted in a PDF reader. For example:
const field = form.getField('some.field')
field.disableExporting()
Returns: void
disableReadOnly
▸ disableReadOnly(): void
Defined in api/form/PDFField.ts:170
Allow users to interact with this field and change its value in PDF readers via mouse and keyboard input. For example:
const field = form.getField('some.field')
field.disableReadOnly()
Returns: void
disableRequired
▸ disableRequired(): void
Defined in api/form/PDFField.ts:208
Do not require this field to have a value when the form is submitted. For example:
const field = form.getField('some.field')
field.disableRequired()
Returns: void
enableExporting
▸ enableExporting(): void
Defined in api/form/PDFField.ts:235
Indicate that this field's value should be exported when the form is submitted in a PDF reader. For example:
const field = form.getField('some.field')
field.enableExporting()
Returns: void
enableReadOnly
▸ enableReadOnly(): void
Defined in api/form/PDFField.ts:158
Prevent PDF readers from allowing users to interact with this field or change its value. The field will not respond to mouse or keyboard input. For example:
const field = form.getField('some.field')
field.enableReadOnly()
Useful for fields whose values are computed, imported from a database, or prefilled by software before being displayed to the user.
Returns: void
enableRequired
▸ enableRequired(): void
Defined in api/form/PDFField.ts:196
Require this field to have a value when the form is submitted. For example:
const field = form.getField('some.field')
field.enableRequired()
Returns: void
getName
▸ getName(): string
Defined in api/form/PDFField.ts:128
Get the fully qualified name of this field. For example:
const fields = form.getFields()
fields.forEach(field => {
const name = field.getName()
console.log('Field name:', name)
})
Note that PDF fields are structured as a tree. Each field is the
descendent of a series of ancestor nodes all the way up to the form node,
which is always the root of the tree. Each node in the tree (except for
the form node) has a partial name. Partial names can be composed of any
unicode characters except a period (.
). The fully qualified name of a
field is composed of the partial names of all its ancestors joined
with periods. This means that splitting the fully qualified name on
periods and taking the last element of the resulting array will give you
the partial name of a specific field.
Returns: string
The fully qualified name of this field.
isExported
▸ isExported(): boolean
Defined in api/form/PDFField.ts:223
Returns true
if this field's value should be exported when the form is
submitted. See PDFField.enableExporting and
PDFField.disableExporting.
For example:
const field = form.getField('some.field')
if (field.isExported()) console.log('Exporting is enabled')
Returns: boolean
Whether or not this field's value should be exported.
isReadOnly
▸ isReadOnly(): boolean
Defined in api/form/PDFField.ts:143
Returns true
if this field is read only. This means that PDF readers
will not allow users to interact with the field or change its value. See
PDFField.enableReadOnly and PDFField.disableReadOnly.
For example:
const field = form.getField('some.field')
if (field.isReadOnly()) console.log('Read only is enabled')
Returns: boolean
Whether or not this is a read only field.
isRequired
▸ isRequired(): boolean
Defined in api/form/PDFField.ts:184
Returns true
if this field must have a value when the form is submitted.
See PDFField.enableRequired and PDFField.disableRequired.
For example:
const field = form.getField('some.field')
if (field.isRequired()) console.log('Field is required')
Returns: boolean
Whether or not this field is required.