modern-pdf-lib / PdfField
Abstract Class: PdfField
Defined in: src/form/pdfField.ts:153
Abstract base class for all AcroForm field types.
Each field holds a reference to the underlying field dictionary (which may be a merged field+widget dictionary in simple forms) and an optional separate widget annotation dictionary.
Extended by
PdfTextFieldPdfCheckboxFieldPdfRadioGroupPdfDropdownFieldPdfListboxFieldPdfButtonFieldPdfSignatureField
Constructors
Constructor
new PdfField(
name,dict,widgetDict,parentNames?):PdfField
Defined in: src/form/pdfField.ts:175
Parameters
name
string
dict
widgetDict
parentNames?
string[] = []
Returns
PdfField
Properties
dict
protectedreadonlydict:PdfDict
Defined in: src/form/pdfField.ts:164
The underlying field dictionary (may contain both field and widget entries for simple one-widget fields).
fieldType
abstractreadonlyfieldType:FieldType
Defined in: src/form/pdfField.ts:155
Discriminator for the concrete field type.
name
readonlyname:string
Defined in: src/form/pdfField.ts:158
The fully-qualified field name.
parentNames
protectedreadonlyparentNames:string[]
Defined in: src/form/pdfField.ts:173
Parent field dictionary chain for building full names.
widgetDict
protectedreadonlywidgetDict:PdfDict
Defined in: src/form/pdfField.ts:170
The widget annotation dictionary. For merged field+widget dicts, this is the same object as dict.
Methods
addToPage()
addToPage(
page):void
Defined in: src/form/pdfField.ts:309
Add this field's widget annotation to a page.
Ensures the widget dict has /Type /Annot and /Subtype /Widget, then adds it to the page's annotation list so it appears in the rendered PDF.
Parameters
page
A page that implements WidgetAnnotationHost.
Returns
void
disableExporting()
disableExporting():
void
Defined in: src/form/pdfField.ts:271
Disable exporting this field (set the NoExport flag).
Returns
void
enableExporting()
enableExporting():
void
Defined in: src/form/pdfField.ts:266
Enable exporting this field (clear the NoExport flag).
Returns
void
generateAppearance()
abstractgenerateAppearance():PdfStream
Defined in: src/form/pdfField.ts:342
Generate the /AP (appearance) stream for this field's current value. Returns a PdfStream suitable for the /N (normal) appearance.
Returns
getFieldFlags()
protectedgetFieldFlags():number
Defined in: src/form/pdfField.ts:211
Get the raw /Ff (field flags) integer value.
Returns
number
getFullName()
getFullName():
string
Defined in: src/form/pdfField.ts:201
Get the fully qualified field name (Parent.Child.Name format). Per PDF spec SS12.7.3.2, the full name is formed by concatenating ancestor /T values with periods.
Returns
string
getName()
getName():
string
Defined in: src/form/pdfField.ts:192
Get the partial field name (/T entry).
Returns
string
getRect()
getRect(): [
number,number,number,number]
Defined in: src/form/pdfField.ts:283
Get the field's widget rectangle as [x1, y1, x2, y2]. The /Rect entry comes from the widget annotation dictionary.
Returns
[number, number, number, number]
getValue()
abstractgetValue():string|boolean|string[]
Defined in: src/form/pdfField.ts:333
Get the current value of this field.
Returns
string | boolean | string[]
hasFlag()
protectedhasFlag(flag):boolean
Defined in: src/form/pdfField.ts:221
Check if a specific flag bit is set.
Parameters
flag
number
Returns
boolean
isExported()
isExported():
boolean
Defined in: src/form/pdfField.ts:261
Whether the field is exported (inverse of NoExport flag).
Returns
boolean
isNoExport()
isNoExport():
boolean
Defined in: src/form/pdfField.ts:256
Whether the field should not be exported.
Returns
boolean
isReadOnly()
isReadOnly():
boolean
Defined in: src/form/pdfField.ts:236
Whether the field is read-only.
Returns
boolean
isRequired()
isRequired():
boolean
Defined in: src/form/pdfField.ts:246
Whether the field is required.
Returns
boolean
setFieldFlags()
protectedsetFieldFlags(flags):void
Defined in: src/form/pdfField.ts:216
Set the raw /Ff (field flags) integer value.
Parameters
flags
number
Returns
void
setFlag()
protectedsetFlag(flag,on):void
Defined in: src/form/pdfField.ts:226
Set or clear a specific flag bit.
Parameters
flag
number
on
boolean
Returns
void
setReadOnly()
setReadOnly(
readOnly):void
Defined in: src/form/pdfField.ts:241
Set the read-only flag.
Parameters
readOnly
boolean
Returns
void
setRequired()
setRequired(
required):void
Defined in: src/form/pdfField.ts:251
Set the required flag.
Parameters
required
boolean
Returns
void
setValue()
abstractsetValue(value):void
Defined in: src/form/pdfField.ts:336
Set the value of this field.
Parameters
value
string | boolean | string[]
Returns
void