Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.interactive.form

public abstract Class PDField

extends Object
implements COSObjectable
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.common.COSObjectable
Known Direct Subclasses
org.apache.pdfbox.pdmodel.interactive.form.PDNonTerminalField, org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField
Imports
java.io.IOException, java.util.List, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSName, .COSStream, .COSString, org.apache.pdfbox.pdmodel.common.COSObjectable, org.apache.pdfbox.pdmodel.fdf.FDFField, org.apache.pdfbox.pdmodel.interactive.action.PDFormFieldAdditionalActions, org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget

A field in an interactive form.

Field Summary

Modifier and TypeField and Description
private final PDAcroForm
private final COSDictionary
private static final int
private static final int
private static final int
private final PDNonTerminalField

Constructor Summary

AccessConstructor and Description
pack-priv
PDField(PDAcroForm
The form that this field is part of.
acroForm
)

Constructor.

pack-priv
PDField(PDAcroForm
The form that this field is part of.
acroForm
,
COSDictionary
the PDF object to represent as a field.
field
,
PDNonTerminalField
the parent node of the node
parent
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract FDFField
exportFDF()

Exports this field and its children as FDF.

pack-priv PDField

Returns:

The field at the endpoint or null if none is found.
findKid
(String[]
An array that picks the path to the field.
name
,
int
The index into the array.
nameIndex
)

This will find one of the child elements.

pack-priv static PDField

Returns:

a new PDField instance
fromDictionary
(PDAcroForm
the form that the field is part of
form
,
COSDictionary
the dictionary representing a field element
field
,
PDNonTerminalField
the parent node of the node to be created, or null if root.
parent
)

Creates a COSField subclass from the given COS field.

public PDAcroForm

Returns:

The form this field is on.
getAcroForm
()

This will get the acroform that this field is part of.

public PDFormFieldAdditionalActions

Returns:

The actions of the field.
getActions
()

Get the additional actions for this field.

public String

Returns:

the alternate name of the field
getAlternateFieldName
()

Gets the alternate name of the field ("shall be used in place of the actual field name wherever the field shall be identified in the user interface (such as in error or status messages referring to the field)").

public COSDictionary

Returns:

the dictionary that this class wraps.
getCOSObject
()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

This will get the dictionary associated with this field.

public abstract int

Returns:

flags The set of flags.
getFieldFlags
()

This will get the flags for this field.

public abstract String

Returns:

The Field type.
getFieldType
()

Get the FT entry of the field.

public String

Returns:

the name of the field
getFullyQualifiedName
()

Returns the fully qualified name of the field, which is a concatenation of the names of all the parents fields.

protected COSBase

Returns:

COS value for the given key
getInheritableAttribute
(COSName
the key to look up
key
)

Returns the given attribute, inheriting from parent nodes if necessary.

public String

Returns:

the mapping name of the field
getMappingName
()

Gets the mapping name of the field.

public PDNonTerminalField

Returns:

The parent field.
getParent
()

Get the parent field to this field, or null if none exists.

public String

Returns:

the name of the field
getPartialName
()

Returns the partial name of the field.

public abstract String

Returns:

The list of widget annotations.
getValueAsString
()

Returns a string representation of the "V" entry, or an empty string.

public abstract List<PDAnnotationWidget>

Returns:

a List of PDAnnotationWidget annotations. Be aware that this list is not backed by the actual widget collection of the field, so adding or deleting has no effect on the PDF document. For PDTerminalField you'd have to call setWidgets() with the modified list.
getWidgets
()

Returns the widget annotations associated with this field.

pack-priv void
importFDF(FDFField
The fdf field to import.
fdfField
)

This will import a fdf field from a fdf document.

public boolean

Returns:

true if the field is not to be exported.
isNoExport
()

public boolean

Returns:

true if the field is readonly
isReadOnly
()

public boolean

Returns:

true if the field is required to have a value at the time it is exported by a submit-form action.
isRequired
()

public void
setAlternateFieldName(String
the alternate name of the field.
alternateFieldName
)

This will set the alternate name of the field ("shall be used in place of the actual field name wherever the field shall be identified in the user interface (such as in error or status messages referring to the field)").

public void
setFieldFlags(int
The new flags.
flags
)

This will set the flags for this field.

public void
setMappingName(String
the mapping name of the field
mappingName
)

This will set the mapping name of the field.

public void
setNoExport(boolean
The new flag for noExport.
noExport
)

sets the field to be not exported.

public void
setPartialName(String
The new name for the field.
name
)

This will set the partial name of the field.

public void
setReadOnly(boolean
The new flag for readonly.
readonly
)

sets the field to be read-only.

public void
setRequired(boolean
The new flag for required.
required
)

sets the flag whether the field is to be required to have a value at the time it is exported by a submit-form action.

public abstract void
setValue(String
the new field value.
value
)

Sets the value of the field.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

acroFormback to summary
private final PDAcroForm acroForm
dictionaryback to summary
private final COSDictionary dictionary
FLAG_NO_EXPORTback to summary
private static final int FLAG_NO_EXPORT
FLAG_READ_ONLYback to summary
private static final int FLAG_READ_ONLY
FLAG_REQUIREDback to summary
private static final int FLAG_REQUIRED
parentback to summary
private final PDNonTerminalField parent

Constructor Detail

PDFieldback to summary
pack-priv PDField(PDAcroForm acroForm)

Constructor.

Parameters
acroForm:PDAcroForm

The form that this field is part of.

PDFieldback to summary
pack-priv PDField(PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)

Constructor.

Parameters
acroForm:PDAcroForm

The form that this field is part of.

field:COSDictionary

the PDF object to represent as a field.

parent:PDNonTerminalField

the parent node of the node

Method Detail

exportFDFback to summary
pack-priv abstract FDFField exportFDF() throws IOException

Exports this field and its children as FDF.

findKidback to summary
pack-priv PDField findKid(String[] name, int nameIndex)

This will find one of the child elements. The name array are the components of the name to search down the tree of names. The nameIndex is where to start in that array. This method is called recursively until it finds the end point based on the name array.

Parameters
name:String[]

An array that picks the path to the field.

nameIndex:int

The index into the array.

Returns:PDField

The field at the endpoint or null if none is found.

fromDictionaryback to summary
pack-priv static PDField fromDictionary(PDAcroForm form, COSDictionary field, PDNonTerminalField parent)

Creates a COSField subclass from the given COS field. This is for reading fields from PDFs.

Parameters
form:PDAcroForm

the form that the field is part of

field:COSDictionary

the dictionary representing a field element

parent:PDNonTerminalField

the parent node of the node to be created, or null if root.

Returns:PDField

a new PDField instance

getAcroFormback to summary
public PDAcroForm getAcroForm()

This will get the acroform that this field is part of.

Returns:PDAcroForm

The form this field is on.

getActionsback to summary
public PDFormFieldAdditionalActions getActions()

Get the additional actions for this field. This will return null if there are no additional actions for this field.

Returns:PDFormFieldAdditionalActions

The actions of the field.

getAlternateFieldNameback to summary
public String getAlternateFieldName()

Gets the alternate name of the field ("shall be used in place of the actual field name wherever the field shall be identified in the user interface (such as in error or status messages referring to the field)").

Returns:String

the alternate name of the field

getCOSObjectback to summary
public COSDictionary getCOSObject()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

This will get the dictionary associated with this field.

Returns:COSDictionary

the dictionary that this class wraps.

Annotations
@Override
getFieldFlagsback to summary
public abstract int getFieldFlags()

This will get the flags for this field.

Returns:int

flags The set of flags.

getFieldTypeback to summary
public abstract String getFieldType()

Get the FT entry of the field. This is a read only field and is set depending on the actual type. The field type is an inheritable attribute.

Returns:String

The Field type.

getFullyQualifiedNameback to summary
public String getFullyQualifiedName()

Returns the fully qualified name of the field, which is a concatenation of the names of all the parents fields.

Returns:String

the name of the field

getInheritableAttributeback to summary
protected COSBase getInheritableAttribute(COSName key)

Returns the given attribute, inheriting from parent nodes if necessary.

Parameters
key:COSName

the key to look up

Returns:COSBase

COS value for the given key

getMappingNameback to summary
public String getMappingName()

Gets the mapping name of the field. The mapping name shall be used when exporting interactive form field data from the document.

Returns:String

the mapping name of the field

getParentback to summary
public PDNonTerminalField getParent()

Get the parent field to this field, or null if none exists.

Returns:PDNonTerminalField

The parent field.

getPartialNameback to summary
public String getPartialName()

Returns the partial name of the field.

Returns:String

the name of the field

getValueAsStringback to summary
public abstract String getValueAsString()

Returns a string representation of the "V" entry, or an empty string.

Returns:String

The list of widget annotations.

getWidgetsback to summary
public abstract List<PDAnnotationWidget> getWidgets()

Returns the widget annotations associated with this field. For PDNonTerminalField the list will be empty as non terminal fields have no visual representation in the form.

Returns:List<PDAnnotationWidget>

a List of PDAnnotationWidget annotations. Be aware that this list is not backed by the actual widget collection of the field, so adding or deleting has no effect on the PDF document. For PDTerminalField you'd have to call setWidgets() with the modified list.

importFDFback to summary
pack-priv void importFDF(FDFField fdfField) throws IOException

This will import a fdf field from a fdf document.

Parameters
fdfField:FDFField

The fdf field to import.

Exceptions
IOException:
If there is an error importing the data for this field.
isNoExportback to summary
public boolean isNoExport()
Returns:boolean

true if the field is not to be exported.

isReadOnlyback to summary
public boolean isReadOnly()
Returns:boolean

true if the field is readonly

isRequiredback to summary
public boolean isRequired()
Returns:boolean

true if the field is required to have a value at the time it is exported by a submit-form action.

setAlternateFieldNameback to summary
public void setAlternateFieldName(String alternateFieldName)

This will set the alternate name of the field ("shall be used in place of the actual field name wherever the field shall be identified in the user interface (such as in error or status messages referring to the field)"). The text appears as a tool tip in Adobe Reader. Because of the usage for error or status messages, it should be different for each field.

Parameters
alternateFieldName:String

the alternate name of the field.

setFieldFlagsback to summary
public void setFieldFlags(int flags)

This will set the flags for this field.

Parameters
flags:int

The new flags.

setMappingNameback to summary
public void setMappingName(String mappingName)

This will set the mapping name of the field.

Parameters
mappingName:String

the mapping name of the field

setNoExportback to summary
public void setNoExport(boolean noExport)

sets the field to be not exported.

Parameters
noExport:boolean

The new flag for noExport.

setPartialNameback to summary
public void setPartialName(String name)

This will set the partial name of the field.

Parameters
name:String

The new name for the field.

Exceptions
IllegalArgumentException:
If the name contains a period character.
setReadOnlyback to summary
public void setReadOnly(boolean readonly)

sets the field to be read-only.

Parameters
readonly:boolean

The new flag for readonly.

setRequiredback to summary
public void setRequired(boolean required)

sets the flag whether the field is to be required to have a value at the time it is exported by a submit-form action.

Parameters
required:boolean

The new flag for required.

setValueback to summary
public abstract void setValue(String value) throws IOException

Sets the value of the field.

Parameters
value:String

the new field value.

Exceptions
IOException:
if the value could not be set
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override