modern-pdf-lib / PdfButtonField
Class: PdfButtonField
Defined in: src/form/fields/buttonField.ts:44
A PDF pushbutton field (/FT /Btn with Pushbutton flag).
Pushbuttons have no permanent value. They may have an associated action (e.g. JavaScript, submit form, reset form) and display a caption via the /MK dictionary.
Extends
Constructors
Constructor
new PdfButtonField(
name,dict,widgetDict,parentNames?):PdfButtonField
Defined in: src/form/pdfField.ts:175
Parameters
name
string
dict
widgetDict
parentNames?
string[] = []
Returns
PdfButtonField
Inherited from
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).
Inherited from
fieldType
readonlyfieldType:FieldType='button'
Defined in: src/form/fields/buttonField.ts:45
Discriminator for the concrete field type.
Overrides
name
readonlyname:string
Defined in: src/form/pdfField.ts:158
The fully-qualified field name.
Inherited from
parentNames
protectedreadonlyparentNames:string[]
Defined in: src/form/pdfField.ts:173
Parent field dictionary chain for building full names.
Inherited from
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.
Inherited from
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
Inherited from
disableExporting()
disableExporting():
void
Defined in: src/form/pdfField.ts:271
Disable exporting this field (set the NoExport flag).
Returns
void
Inherited from
enableExporting()
enableExporting():
void
Defined in: src/form/pdfField.ts:266
Enable exporting this field (clear the NoExport flag).
Returns
void
Inherited from
generateAppearance()
generateAppearance():
PdfStream
Defined in: src/form/fields/buttonField.ts:145
Generate the appearance stream for this button.
Returns
Overrides
getCaption()
getCaption():
string|undefined
Defined in: src/form/fields/buttonField.ts:55
Get the button caption from the /MK dictionary. Returns undefined if no caption is set.
Returns
string | undefined
getFieldFlags()
protectedgetFieldFlags():number
Defined in: src/form/pdfField.ts:211
Get the raw /Ff (field flags) integer value.
Returns
number
Inherited from
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
Inherited from
getName()
getName():
string
Defined in: src/form/pdfField.ts:192
Get the partial field name (/T entry).
Returns
string
Inherited from
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]
Inherited from
getValue()
getValue():
string
Defined in: src/form/fields/buttonField.ts:131
Pushbuttons have no value; returns empty string.
Returns
string
Overrides
hasFlag()
protectedhasFlag(flag):boolean
Defined in: src/form/pdfField.ts:221
Check if a specific flag bit is set.
Parameters
flag
number
Returns
boolean
Inherited from
isExported()
isExported():
boolean
Defined in: src/form/pdfField.ts:261
Whether the field is exported (inverse of NoExport flag).
Returns
boolean
Inherited from
isNoExport()
isNoExport():
boolean
Defined in: src/form/pdfField.ts:256
Whether the field should not be exported.
Returns
boolean
Inherited from
isReadOnly()
isReadOnly():
boolean
Defined in: src/form/pdfField.ts:236
Whether the field is read-only.
Returns
boolean
Inherited from
isRequired()
isRequired():
boolean
Defined in: src/form/pdfField.ts:246
Whether the field is required.
Returns
boolean
Inherited from
setCaption()
setCaption(
caption):void
Defined in: src/form/fields/buttonField.ts:67
Set the button caption in the /MK dictionary. Creates the /MK dictionary if it does not exist.
Parameters
caption
string
Returns
void
setFieldFlags()
protectedsetFieldFlags(flags):void
Defined in: src/form/pdfField.ts:216
Set the raw /Ff (field flags) integer value.
Parameters
flags
number
Returns
void
Inherited from
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
Inherited from
setImage()
setImage(
imageRef):void
Defined in: src/form/fields/buttonField.ts:90
Set an image on this button field.
Creates an appearance stream that paints the image XObject scaled to fit the widget rectangle.
Parameters
imageRef
An object with name (resource name) and ref (PdfRef) pointing to the image XObject, plus width and height.
height
number
name
string
ref
width
number
Returns
void
setReadOnly()
setReadOnly(
readOnly):void
Defined in: src/form/pdfField.ts:241
Set the read-only flag.
Parameters
readOnly
boolean
Returns
void
Inherited from
setRequired()
setRequired(
required):void
Defined in: src/form/pdfField.ts:251
Set the required flag.
Parameters
required
boolean
Returns
void
Inherited from
setValue()
setValue(
_value):void
Defined in: src/form/fields/buttonField.ts:136
Pushbuttons have no value; no-op.
Parameters
_value
string | boolean | string[]
Returns
void