Class PDField
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.interactive.form.PDField
-
- All Implemented Interfaces:
COSObjectable
- Direct Known Subclasses:
PDChoiceButton,PDPushButton,PDSignature,PDSignatureField,PDUnknownField,PDVariableText
public abstract class PDField extends java.lang.Object implements COSObjectable
This is the superclass for a Field element in a PDF. Based on the COS object model from PDFBox.- Author:
- sug
-
-
Field Summary
Fields Modifier and Type Field Description static intFLAG_NO_EXPORTA Ff flag.static intFLAG_READ_ONLYA Ff flag.static intFLAG_REQUIREDA Ff flag.
-
Constructor Summary
Constructors Constructor Description PDField(PDAcroForm theAcroForm)Constructor.PDField(PDAcroForm theAcroForm, COSDictionary field)Creates a COSField from a COSDictionary, expected to be a correct object definition for a field in PDF.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.StringfindFieldType()Find the field type and optionally do a recursive upward search.PDFieldfindKid(java.lang.String[] name, int nameIndex)This will find one of the child elements.PDAcroFormgetAcroForm()This will get the acroform that this field is part of.PDFormFieldAdditionalActionsgetActions()Get the additional actions for this field.java.lang.StringgetAlternateFieldName()Gets the alternate name of the field.COSBasegetCOSObject()Convert this standard java object to a COS object.COSDictionarygetDictionary()This will get the dictionary associated with this field.intgetFieldFlags()This will get the flags for this field.java.lang.StringgetFieldType()Get the FT entry of the field.java.lang.StringgetFullyQualifiedName()Returns the fully qualified name of the field, which is a concatenation of the names of all the parents fields.java.util.List<COSObjectable>getKids()This will get all the kids of this field.PDFieldgetParent()Get the parent field to this field, or null if none exists.java.lang.StringgetPartialName()Returns the partial name of the field.abstract java.lang.StringgetValue()getValue gets the fields value to as a string.PDAnnotationWidgetgetWidget()This will get the single associated widget that is part of this field.java.util.List<PDAnnotationWidget>getWidgets()Returns the widget annotations associated with this field.voidimportFDF(FDFField fdfField)This will import a fdf field from a fdf document.booleanisNoExport()booleanisReadonly()booleanisRequired()voidsetAcroForm(PDAcroForm value)This will set the form this field is on.voidsetActions(PDFormFieldAdditionalActions actions)Set the actions of the field.voidsetAlternateFieldName(java.lang.String alternateFieldName)This will set the alternate name of the field.voidsetFieldFlags(int flags)This will set the flags for this field.protected voidsetFieldType(java.lang.String fieldType)Set the field type.voidsetKids(java.util.List<COSObjectable> kids)This will set the list of kids.voidsetNoExport(boolean noExport)sets the field to be not exported..voidsetParent(PDField parent)Set the parent of this field.voidsetPartialName(java.lang.String name)This will set the partial name of the field.voidsetReadonly(boolean readonly)sets the field to be read-only.voidsetRequired(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.abstract voidsetValue(java.lang.String value)setValue sets the fields value to a given string.java.lang.StringtoString()This will return a string representation of this field.
-
-
-
Field Detail
-
FLAG_READ_ONLY
public static final int FLAG_READ_ONLY
A Ff flag.- See Also:
- Constant Field Values
-
FLAG_REQUIRED
public static final int FLAG_REQUIRED
A Ff flag.- See Also:
- Constant Field Values
-
FLAG_NO_EXPORT
public static final int FLAG_NO_EXPORT
A Ff flag.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PDField
public PDField(PDAcroForm theAcroForm)
Constructor.- Parameters:
theAcroForm- The form that this field is part of.
-
PDField
public PDField(PDAcroForm theAcroForm, COSDictionary field)
Creates a COSField from a COSDictionary, expected to be a correct object definition for a field in PDF.- Parameters:
theAcroForm- The form that this field is part of.field- the PDF objet to represent as a field.
-
-
Method Detail
-
getPartialName
public java.lang.String getPartialName()
Returns the partial name of the field.- Returns:
- the name of the field
-
setPartialName
public void setPartialName(java.lang.String name)
This will set the partial name of the field.- Parameters:
name- The new name for the field.
-
getFullyQualifiedName
public java.lang.String getFullyQualifiedName() throws java.io.IOExceptionReturns the fully qualified name of the field, which is a concatenation of the names of all the parents fields.- Returns:
- the name of the field
- Throws:
java.io.IOException- If there is an error generating the fully qualified name.
-
getAlternateFieldName
public java.lang.String getAlternateFieldName()
Gets the alternate name of the field.- Returns:
- the alternate name of the field
-
setAlternateFieldName
public void setAlternateFieldName(java.lang.String alternateFieldName)
This will set the alternate name of the field.- Parameters:
alternateFieldName- the alternate name of the field
-
getFieldType
public java.lang.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. This method will return only the direct value on this object. Use the findFieldType for an upward recursive search.- Returns:
- The Field type.
- See Also:
findFieldType()
-
findFieldType
public java.lang.String findFieldType()
Find the field type and optionally do a recursive upward search. Sometimes the fieldtype will be specified on the parent instead of the direct object. This will look at this object for the field type, if none is specified then it will look to the parent if there is a parent. If there is no parent and no field type has been found then this will return null.- Returns:
- The field type or null if none was found.
-
setValue
public abstract void setValue(java.lang.String value) throws java.io.IOExceptionsetValue sets the fields value to a given string.- Parameters:
value- the string value- Throws:
java.io.IOException- If there is an error creating the appearance stream.
-
getValue
public abstract java.lang.String getValue() throws java.io.IOExceptiongetValue gets the fields value to as a string.- Returns:
- The string value of this field.
- Throws:
java.io.IOException- If there is an error getting the value.
-
setReadonly
public void setReadonly(boolean readonly)
sets the field to be read-only.- Parameters:
readonly- The new flag for readonly.
-
isReadonly
public boolean isReadonly()
- Returns:
- true if the field is readonly
-
setRequired
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- The new flag for required.
-
isRequired
public boolean isRequired()
- Returns:
- true if the field is required to have a value at the time it is exported by a submit-form action.
-
setNoExport
public void setNoExport(boolean noExport)
sets the field to be not exported..- Parameters:
noExport- The new flag for noExport.
-
isNoExport
public boolean isNoExport()
- Returns:
- true if the field is not to be exported.
-
getFieldFlags
public int getFieldFlags()
This will get the flags for this field.- Returns:
- flags The set of flags.
-
setFieldFlags
public void setFieldFlags(int flags)
This will set the flags for this field.- Parameters:
flags- The new flags.
-
importFDF
public void importFDF(FDFField fdfField) throws java.io.IOException
This will import a fdf field from a fdf document.- Parameters:
fdfField- The fdf field to import.- Throws:
java.io.IOException- If there is an error importing the data for this field.
-
getWidget
public PDAnnotationWidget getWidget() throws java.io.IOException
This will get the single associated widget that is part of this field. This occurs when the Widget is embedded in the fields dictionary. Sometimes there are multiple sub widgets associated with this field, in which case you want to usegetWidgets(). If the kids entry is specified, then only first entry in that list will be returned.- Returns:
- The widget that is associated with this field.
- Throws:
java.io.IOException- If there is an error getting the widget object.
-
getWidgets
public java.util.List<PDAnnotationWidget> getWidgets()
Returns the widget annotations associated with this field. The widget annotations are returned for terminal fields (fields which do not have other fields as kids). In case of non terminal fields an empty List is returned.- Returns:
- The list of widget annotations.
-
getParent
public PDField getParent() throws java.io.IOException
Get the parent field to this field, or null if none exists.- Returns:
- The parent field.
- Throws:
java.io.IOException- If there is an error creating the parent field.
-
setParent
public void setParent(PDField parent)
Set the parent of this field.- Parameters:
parent- The parent to this field.
-
findKid
public PDField findKid(java.lang.String[] name, int nameIndex) throws java.io.IOException
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- An array that picks the path to the field.nameIndex- The index into the array.- Returns:
- The field at the endpoint or null if none is found.
- Throws:
java.io.IOException- If there is an error creating the field.
-
getKids
public java.util.List<COSObjectable> getKids() throws java.io.IOException
This will get all the kids of this field. The values in the list will either be PDWidget or PDField. Normally they will be PDWidget objects unless this is a non-terminal field and they will be child PDField objects.- Returns:
- A list of either PDWidget or PDField objects.
- Throws:
java.io.IOException- If there is an error retrieving the kids.
-
setKids
public void setKids(java.util.List<COSObjectable> kids)
This will set the list of kids.- Parameters:
kids- The list of child widgets.
-
toString
public java.lang.String toString()
This will return a string representation of this field.- Overrides:
toStringin classjava.lang.Object- Returns:
- A string representation of this field.
-
getAcroForm
public PDAcroForm getAcroForm()
This will get the acroform that this field is part of.- Returns:
- The form this field is on.
-
setAcroForm
public void setAcroForm(PDAcroForm value)
This will set the form this field is on.- Parameters:
value- The new form to use.
-
getDictionary
public COSDictionary getDictionary()
This will get the dictionary associated with this field.- Returns:
- The dictionary that this class wraps.
-
getCOSObject
public COSBase getCOSObject()
Convert this standard java object to a COS object.- Specified by:
getCOSObjectin interfaceCOSObjectable- Returns:
- The cos object that matches this Java object.
-
getActions
public PDFormFieldAdditionalActions getActions()
Get the additional actions for this field. This will return null if there are no additional actions for this field.- Returns:
- The actions of the field.
-
setActions
public void setActions(PDFormFieldAdditionalActions actions)
Set the actions of the field.- Parameters:
actions- The field actions.
-
setFieldType
protected void setFieldType(java.lang.String fieldType)
Set the field type.- Parameters:
fieldType- the field type string must be one of "Btn", "Ch", "Tx", "Sig"
-
-